Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration in springboot

Viewed 1361

Getting error while saving record in DB in spring boot. please find the code and error details as below:

Main class:

package *.*.*;

@SpringBootApplication
public class BankApplication {

    public static void main(String[] args) {
        SpringApplication.run(BankApplication.class, args);
    }

}

Repository

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);     

    }
}

app.properties:

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 message is below:

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

getting above error while calling saveAndFlush()in DBUtils from another class. Can anyone please help me on this.

1 Answers

Try to add the dialect to your application.properties file like below

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