gpt4 book ai didi

java - 在 springboot 中创建名为 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration 的 bean 时出错

转载 作者:行者123 更新时间:2023-12-05 07:05:54 34 4
gpt4 key购买 nike

在 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com