在 spring boot 中将记录保存到数据库时出错。请在下面找到代码和错误详细信息:
主类:
package *.*.*;
@SpringBootApplication
public class BankApplication {
public static void main(String[] args) {
SpringApplication.run(BankApplication.class, args);
}
}
存储库
package *.*.*.dataaccess.repository;
@Repository
public interface BankRepository extends JpaRepository<BankEntity, String> {
}
package *.*.*.dataaccess.dao;
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "Bank")
public class BankEntity {
//fields
}
package *.*.*.dataaccess.utils;
@Component
public class DBUtils {
@Autowired
BankRepository bnRepo;
*/
public void saveBank(BankDto dto) {
//preparing bnEntity -entity
this.bnRepo.saveAndFlush(bnEntity);
}
}
spring.jpa.database=mysql
spring.datasource.url=jdbc:mysql://${DATABASE_SRV}/?&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.datasource.username=${USER}
spring.datasource.password=${PASS}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# HIBERNATE
spring.jpa.properties.hibernate.proc.param_null_passing=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a18f23c has not been refreshed yet
从另一个类调用 DBUtils 中的 saveAndFlush() 时出现上述错误。谁能帮我解决这个问题。
最佳答案
尝试将方言添加到您的 application.properties 文件中,如下所示
##Hibernate DDL Auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
关于java - 在 springboot 中创建名为 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration 的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62655700/
相关文章:
node.js - NodeMailer - G-Suite - 服务账户 - 以群组邮件形式发送
python - 在 Django 项目中从 Scrapy 获取蜘蛛列表
c# - CreatedAtAction 结果为 "No route matches the sup
testing - 在 Cypress 中运行测试的所有断言
amazon-web-services - 使用 bitbucket codestar 连接手动触发
react-native - 当应用程序已经安装时,如何从 React Native 中的实际应用程
node.js - 如何在服务器端渲染中使用 Mongodb