I'm trying out a spring-boot-starter project. And trying out a simple project with jpa with a POSTGRES db behind it. However when launching the app I get a ClassNotFoundException
:
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.ImplicitNamingStrategy
But how is that possible? I thought the spring-boot-starter-jpa would dependency in maven would take care of all the required dependencies...
@Configuration
@PropertySource("classpath:application.properties")
public class AuthConfiguration {
@Value("${hibernate.driver_class}")
private String DATABASE_DRIVER_CLASS;
@Value("${hibernate.url}")
private String DATABASE_URL;
@Value("${hibernate.username}")
private String DATABASE_USER;
@Value("${hibernate.password}")
private String DATABASE_PASSWORD;
@Value("${hibernate.dialect}")
private String HIBERNATE_DIALECT;
@Value("${hibernate.packages_to_scan}")
private String HIBERNATE_PACKAGES_TO_SCAN;
@Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(DATABASE_DRIVER_CLASS);
dataSource.setUrl(DATABASE_URL);
dataSource.setUsername(DATABASE_USER);
dataSource.setPassword(DATABASE_PASSWORD);
return dataSource;
}
@Bean
public HibernateTransactionManager transactionManager() {
final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
@Bean
public LocalSessionFactoryBean sessionFactory() {
final LocalSessionFactoryBean localSessionFactoryBean =
new LocalSessionFactoryBean();
localSessionFactoryBean.setDataSource(dataSource());
localSessionFactoryBean.setPackagesToScan(HIBERNATE_PACKAGES_TO_SCAN);
{
final Properties properties = new Properties();
properties.put("hibernate.dialect", HIBERNATE_DIALECT);
localSessionFactoryBean.setHibernateProperties(properties);
}
return localSessionFactoryBean;
}
}
The properties I am using
hibernate.driver_class = org.postgresql.Driver
hibernate.datasource_class = org.postgresql.ds.PGSimpleDataSource
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
hibernate.url = jdbc:postgresql://localhost:5432/test
hibernate.username = postgres
hibernate.password = password
hibernate.show_sql=false
hibernate.generate_statistics=false
hibernate.packages_to_scan=com.test.model
Here is my maven setup
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>auth</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>auth</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
<!--
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I don't know how to fix this. Adding hibernate-core dependency itself didn't solve it either as I read on another stackoverflow post, but it feels bad as well to do so because everything should be in the starter dependency...
Any ideas what I am missing?
Spring Boot: Accessing Data with JPA
tutorial: spring.io/guides/gs/accessing-data-jpa β Xtreme Biker