Solution:
First remove all of your configuration Spring Boot will begin it for you. In case you truly require a SessionFactory
instead of an EntityManagerFactory
include a HibernateJpaSessionFactoryBean
.
Ensure that you have an application.properties
in your classpath and include the following properties.
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/teste?charSet=LATIN1
spring.datasource.username=klebermo
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create
In case you truly require access to a SessionFactory
and that is originally for the similar data source, then you can do the following (which is further docmented here although for XML, not JavaConfig).
@Configuration
public class HibernateConfig {
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
factory.setEntityManagerFactory(emf);
return factory;
}
}
That method you have both an EntityManagerFactory
and a SessionFactory
.
Pretending you have a class with a main
method with @EnableAutoConfiguration
you don't require the @EnableTransactionManagement
annotation, as that will be enabled by Spring Boot for you. A basic application class in the com.spring.app
package must be enough.
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Something like that must be enough to have all your classes (together with entities and Spring Data based repositories) detected.
I would also point out removing the commons-dbcp
dependency as that would approve Spring Boot to configure the faster and more robust HikariCP
implementation.
Including the following line to the properties
file solve this problem at the time I had that error
spring.jpa.database=mysql