在 springboot 中创建名为 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration 的 bean



在春季启动时将记录保存在数据库中时出错。 请找到代码和错误详细信息,如下所示:

主类:

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((时出现上述错误。任何人都可以帮我解决这个问题。

尝试将方言添加到您的应用程序.属性文件中,如下所示

##Hibernate DDL Auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

相关内容

最新更新