SpringBoot + Mybatis + MySQL, java.lang.IllegalStateException: Failed to load ApplicationContext - java

I am very new to Spring. I am using SpringBoot + Mybatis + MySQL, I have this exception when I did my Unit test for my UserDAO : "java.lang.IllegalStateException: Failed to load ApplicationContext". I follow this link to setting up my testing environment: http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-test-autoconfigure/. I have searched a lot, but still can't find a solution. Could someone give me some advice? Thanks a lot in advance :)
Here is my Mybatis config file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<settings>
<!-- Globally enables or disables any caches configured in any mapper under this configuration -->
<setting name="cacheEnabled" value="true"/>
<!-- Sets the number of seconds the driver will wait for a response from the database -->
<setting name="defaultStatementTimeout" value="3000"/>
<!-- Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- Allows JDBC support for generated keys. A compatible driver is required.
This setting forces generated keys to be used if set to true,
as some drivers deny compatibility but still work -->
<setting name="useGeneratedKeys" value="true"/>
</settings>
<!-- Continue going here -->
</configuration>
Here is my pom.file:
<?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.jingjie</groupId>
<artifactId>forum_demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>forum_demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
And here is my UserDao
#Mapper
public interface UserDao {
static final String USER_TABLE = "user";
final String INSERT_FIELDS = " name, password, salt, head_url";
final String SELECT_FIELDS = " id, name, password, salt, head_url";
// insert a record into user table
#Insert({"Insert into ", USER_TABLE, " (" + INSERT_FIELDS + ") values " +
"(#{name}, #{password}, #{salt}, #{headUrl})"})
void addUser(User user);
// select a record according to a given user id
#Select({"select ", SELECT_FIELDS, " from ", USER_TABLE, " where id = #
{id}"})
User getUserViaId(int id);
// select a record according to a given user name
#Select({"select ", SELECT_FIELDS , " from ", USER_TABLE, " where name = #
{name}"})
User getUserViaName(String name);
// update a user's password accroding to a given user id
#Update({"update ", USER_TABLE, " set password = #{password} where id = #
{id}"})
void updatePassword(int id);
// delete a record accroding to a given user id
#Delete({"delete from ", USER_TABLE, " where id = #{id]"})
void deleteRecordViaId(int id);
}
Here is my applications.properties:
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/forum_demo?
useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=*****
mybatis.config-location=classpath:src/main/resources/mybatis-config.xml
Here is my Test class:
package com.jingjie.forum_demo.daotest;
import com.jingjie.forum_demo.dao.UserDao;
import com.jingjie.forum_demo.model.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Random;
#RunWith(SpringRunner.class)
//#SpringBootApplication
#EnableAutoConfiguration
#MybatisTest
//#AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Rplace.NONE)
//#Sql("/forum_demo.sql")
public class UserDaoTest {
#Autowired
UserDao userDaoTest;
#Test
public void addUserTest() {
Random random = new Random();
for (int i = 0; i < 11; i ++) {
// perform some test
}
}
}
Here is the testing fail info:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.jingjie.forum_demo.daotest.UserDaoTest]; nested exception is java.lang.IllegalStateException: Unable to read meta-data for class org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:556)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: java.lang.IllegalStateException: Unable to read meta-data for class org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationMetadata(AutoConfigurationSorter.java:217)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationValue(AutoConfigurationSorter.java:198)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.readBefore(AutoConfigurationSorter.java:186)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.<init>(AutoConfigurationSorter.java:158)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClasses.<init>(AutoConfigurationSorter.java:115)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter.getInPriorityOrder(AutoConfigurationSorter.java:57)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.sort(AutoConfigurationImportSelector.java:241)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:98)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:547)
... 38 more
Caused by: java.io.FileNotFoundException: class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:50)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:89)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:76)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:93)
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationMetadata(AutoConfigurationSorter.java:213)
... 46 more
Process finished with exit code 255

I have solved the problem, I used the wrong package for Mybatis in pom.file. That is why due to the code is correct, but it shows such an error

Related

Spring Boot - DataSource from JNDI: NoInitialContextException: Need to specify class name in environment or system property

I am relatively new to web apps with spring boot so bear with me.
Problem When I run my spring boot app I get
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc/spring-jdbc-test'; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration.dataSource(JndiDataSourceAutoConfiguration.java:61) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration$$EnhancerBySpringCGLIB$$495e06f0.CGLIB$dataSource$0(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration$$EnhancerBySpringCGLIB$$495e06f0$$FastClassBySpringCGLIB$$7a21dc8c.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration$$EnhancerBySpringCGLIB$$495e06f0.dataSource(<generated>) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_102]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 59 common frames omitted
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) ~[na:1.8.0_102]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) ~[na:1.8.0_102]
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350) ~[na:1.8.0_102]
at javax.naming.InitialContext.lookup(InitialContext.java:417) ~[na:1.8.0_102]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 70 common frames omitted
The line Failed to look up JNDI DataSource with name 'jdbc/spring-jdbc-test' gives me suspicions that the app runs on its own tomcat server and not the one that I have installed.
The app starts on tomcat 8.5.23 as configured in my pom (see below)
2017-12-20 13:22:35.477 INFO 19188 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-12-20 13:22:35.478 INFO 19188 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
In eclipse I added a tomcat server of that version, added the sqlite jar to catalina.base/lib/ and configured the JNDI resource in catalina.base/conf/context.xml
<Resource
auth="Container"
driverClassName="org.sqlite.JDBC"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/spring-jdbc-test"
type="javax.sql.DataSource"
url="jdbc:sqlite:/${catalina.home}/databases/spring-test.sqlite">
</Resource>
application.properties
#server.tomcat.basedir=C:\Dev\tomcat\apache-tomcat-8.5.23\ <-- Error when I uncomment this
spring.datasource.jndi-name=jdbc/spring-jdbc-test
POM
<?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>spring.jdbc.demo</groupId>
<artifactId>spring-demo-jdbc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-demo-jdbc</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.23</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</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>
App
#SpringBootApplication
#ComponentScan(basePackages="spring.jdbc.demo.*")
public class SpringDemoJdbcApplication {
public static void main(String[] args) {
SpringApplication.run(SpringDemoJdbcApplication.class, args);
}
}
Class that uses DataSource
#Repository
public class JdbcMessageDAO implements MessageDAO
{
private static final String SELECT_STATEMENT = "SELECT id, name, message FROM MESSAGES WHERE id=?";
private static final String SELECT_ALL_STATEMENT = "SELECT id, name, message FROM MESSAGES";
private final JdbcTemplate jdbcTemplate;
#Autowired
public JdbcMessageDAO(DataSource dataSource)
{
jdbcTemplate = new JdbcTemplate(dataSource);
}
/*...*/
}
Thanks for the help!
I just ironed out this issue in Tomcat 9. What you have looks fine, and is just missing two things from what worked for me:
a #Resource annotation in your Spring Configuration. Something like:
#Configuration
public class AppManifest {
#Resource(name = "jdbc/spring-jdbc-test", lookup = "jdbc/spring-jdbc-test") private javax.sql.DataSource springJdbcTest;
}
application.properties:
spring.datasource.jndi-name=java:comp/env/jdbc/spring-jdbc-test

Database connection failing in spring boot application

I am trying to deploy the spring boot application with built in Tomcat Server. And, I am getting the below error before even the application gets started.
Field error in object 'spring.datasource' on field 'type': rejected value [org.apache.tomcat.dbcp.dbcp2.BasicDataSource]; codes [typeMismatch.spring.datasource.type,typeMismatch.type,typeMismatch.java.lang.Class,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.datasource.type,type]; arguments []; default message [type]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'type'; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.apache.tomcat.dbcp.dbcp2.BasicDataSource]] - o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext
2017-11-26 22:18:27:489 - INFO - Correlation-Id = - AppName = - Server-IP = - RequestorApp = - RequestorIp = - UserId = - Total-Time = -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. - o.s.b.a.l.AutoConfigurationReportLoggingInitializer
2017-11-26 22:18:27:492 - ERROR - Correlation-Id = - AppName = - Server-IP = - RequestorApp = - RequestorIp = - UserId = - Total-Time = -
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#466317f failed:
Property: spring.datasource.type
Value: org.apache.tomcat.dbcp.dbcp2.BasicDataSource
Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'type'; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.apache.tomcat.dbcp.dbcp2.BasicDataSource]
Action:
Update your application's configuration
- o.s.b.d.LoggingFailureAnalysisReporter
Given below is my pom.xml file
<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.cnanational.productservice</groupId>
<artifactId>product-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>product-service</name>
<description>Product Service</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss z</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cnanational.servicecommon</groupId>
<artifactId>service-common</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>8.5.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven-releases</id>
<name>CNA National Release Artifacts</name>
<url>https://nexus.cnanational.net/repository/maven-releases/</url>
</repository>
<repository>
<id>maven-snapshots</id>
<name>CNA National Snapshot Artifacts</name>
<url>https://nexus.cnanational.net/repository/maven-snapshots/</url>
</repository>
<repository>
<id>maven-central</id>
<name>CNA National Central</name>
<url>https://nexus.cnanational.net/repository/maven-central/</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>
**/product-service/
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Given below is the spring-boot yml file.
security:
user:
name: qcSa
password: qcPassword
server:
port: 8100
context-path: /product-service
endpoints:
jmx:
domain: com.cnanational.productservice
management:
context-path: /${common.application-version}/actuator
spring:
application:
name: product-service
datasource:
# jndi-name: jdbc/web_base_user
url: jdbc:oracle:thin:#devrac-scan.cnanational.net:1521/d02wpa.cnanational.net
username: web_base_user
password: ubew6130
type: org.apache.tomcat.dbcp.dbcp2.BasicDataSource
product-service:
paths:
product-attributes: '/dealerProductAttributes'
product-surcharges: '/surcharges'
product-products: '/products'
deductible-descriptions:
S: Standard
D: Disappearing
sales-ws:
validation-rules-endpoint:
endpoint: https://dev03tc.cnanational.com/sales-ws/v1/uiGlobalSettings/search?appName=SalesRatingTool
user: SVC_DEV_CORS
password: 113501*3Q3E105^9^z7b
sql-properties:
product-procedure-no-rates-error-code: 20000
controlobj-sql: >
begin begin dbms_session.set_role(controlobj.getdisableddbroles);
exception when others then null;
end;
controlobj.web_set_user('%s', 'N','%s');
end;
controlobj-clear-errors-sql: >
call errorobj.clearerrormessage()
controlobj-query-errors-sql: >
select error_message from error_messagev1
agent-sales-rating-id-seq-sql:
select agent_sales_rating_id_seq.nextval from dual
rate-insertion-sql: >
insert into agent_sales_rating_parms
(agent_sales_rating_id, parm_name, parm_value1, parm_value2, parm_value3)
values
(:agent_sales_rating_id, :parm_name, :parm_value1, :parm_value2, :parm_value3)
rate-procedure-name: ins_agent_sales_rating_outputs
rate-params-query-sql: >
select
agent_sales_rating_id,
parm_name,
parm_value1,
parm_value2,
parm_value3
from
agent_sales_rating_parms
where
agent_sales_rating_id = :agent_sales_rating_id
and parm_name in (:param_names)
rate-query-sql: >
select
listagg(model_description,',') WITHIN GROUP ( order by model_description) as model
,vehicle_class
,term_months
,term_miles
, series_deductibles_id
, deduct_option
, deduct_amt
, retail_price
, dealer_cost
from
agent_sales_rating_outputs
where
agent_sales_rating_id = :agent_sales_rating_id
group by
vehicle_class
, term_months
, term_miles
, series_deductibles_id
, deduct_option
, deduct_amt
, retail_price
, dealer_cost
order by
vehicle_class desc
, series_deductibles_id
, deduct_option
, deduct_amt
, term_months
, term_miles
common:
application-version: v1
message-automation:
app-name: product-service
heavyweight: false
fallback-message: 'A system error has occurred'
message-ids:
common-exception-handler: 600000
common-error-controller: 600003
required-headers-filter: 600012
too-many-sort-arguments: 600011
invalid-sort-field: 600010
rest:
paths:
build-info: /buildInfo
remote-user-header-required-urls:
- /v1/**
headers:
remote-user: oam_remote_user
correlation-id: Correlation-Id
requestor-app: REQUESTOR_APP
health:
dependencies:
-
name: 'Oracle Datasource'
dependency-type: DB
Below is the context.xml file which has the beans information. And the Java class below has the application properties.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="timeElapsedAspect" class="com.cnanational.servicecommon.aop.TimeElapsedAspect"></bean> <aop:config> <aop:aspect id="timeElapsedAspect" ref="timeElapsedAspect"> <aop:pointcut id="controllerPointcut" expression="execution(public * com.cnanational.productsservice.controller.*.*(..))"/> <aop:around method="logTimeElapsed" pointcut-ref="controllerPointcut"/> </aop:aspect> </aop:config> </beans>
package com.cnanational.productservice;
import java.util.Properties;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.ResourceBundleMessageSource;
import com.cnanational.productservice.config.ProductProperties;
import com.cnanational.servicecommon.config.CommonConfiguration;
#SpringBootApplication
#EnableConfigurationProperties({ ProductProperties.class })
#Import({ CommonConfiguration.class })
#ImportResource({ "classpath:/product-service/context.xml" })
public class ProductServiceApplication
{
public static final String PROFILE_TEST = "test";
public static void main(String[] args) 
{
new SpringApplicationBuilder(ProductServiceApplication.class)
.sources(ProductServiceApplication.class)
.properties(properties())
.run(args);
}
public static Properties properties()
{
Properties props = new Properties();
props.put("spring.config.location", "classpath:product-service/");
props.put("spring.config.name", "product-service");
props.put("logging.config", "classpath:product-service/logback.xml");
return props;
}
#Bean
public MessageSource messageSource()
{
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("product-service/ValidationMessages");
messageSource.setUseCodeAsDefaultMessage(false);
return messageSource;
}
/**
 * JUnit test configuration only to be applied when test profile
 * is active.  This is required for inherited tests to work without
 * having to add the EnableAutoConfiguration tag to every concrete
 * test class.
 */
#Profile(PROFILE_TEST)
#Configuration
#EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public static class TestConfiguration
{
private final Logger log = LoggerFactory.getLogger(getClass());
/**
 * Let us know that the test configuration is loaded. 
 */
#PostConstruct
public void postConstruct()
{
log.info("TestConfiguration loaded");
}
}
}

HIbernate Maven project: No Persistence provider for EntityManager named

I am working on a JPA tutorial and running into issues when trying to unit test. I am working with Apache Derby and Hibernate.
Here is my sample code files;
persistence.xml
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.agonical.book.pojo.Book</class>
<properties>
<property name="javax.persistence.schema-generation-action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation-target" value="database-and-scripts"/>
<property name="javax.persistence.jdbc.driver" value="com.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/chapter4DB;create=true"/>
<property name="javax.persistence.sql-load-script-source" value="insert.sql"/>
<property name="show_sql" value="true"/>
<property name="dialect" value="org.hibernate.dialect.DerbyDialect"/>
</properties>
</persistence-unit>
Test.class
private static EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test");
private EntityManager entityManager;
private EntityTransaction transaction;
#Before
public void initEntityManager() throws Exception {
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction();
}
#After
public void closeEntityManager() throws Exception {
if(entityManager != null){
entityManager.close();
}
}
#Test
public void shouldFindJavaEE7Book() throws Exception {
Book book = entityManager.find(Book.class, 1001L);
assertEquals("Beginning Java EE 7", book.getTitle());
}
pom.xml
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.11.1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
Error when unit testing
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named test
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at org.agonical.book.BookIT.<clinit>(BookIT.java:19)
... 21 more
The persistence.xml is located in the src/test/resources/META-INF dir. I did have the test persistence-unit in the one persistence.xml file in src/main/resources/META-INF dir.
Each ends with the same result. I have been doing numerous research online and from what I can see I am doing everything correctly and don't understand why this is not working.
Any help would be greatly appreciated.
Try adding dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.0.Final</version> // or whatever version you use
</dependency>
to your pom dependencies.
Currently you have only API.

Cannot configure Spring Boot

I am trying to make a simple 'Hello World' application with Spring Boot. After following the tutorial from the Spring website, I am getting the following error:
SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
12:51:10.775 [main] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/zipfs.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfxswt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/rt.jar, file:/C:/Users/nabil/IdeaProjects/TestSpringFramework/target/classes/, file:/C:/Users/nabil/.m2/repository/org/thymeleaf/thymeleaf/3.0.5.RELEASE/thymeleaf-3.0.5.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/ognl/ognl/3.1.12/ognl-3.1.12.jar, file:/C:/Users/nabil/.m2/repository/org/javassist/javassist/3.20.0-GA/javassist-3.20.0-GA.jar, file:/C:/Users/nabil/.m2/repository/org/attoparser/attoparser/2.0.3.RELEASE/attoparser-2.0.3.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/unbescape/unbescape/1.1.4.RELEASE/unbescape-1.1.4.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/slf4j/slf4j-api/1.6.6/slf4j-api-1.6.6.jar, file:/C:/Users/nabil/.m2/repository/org/thymeleaf/extras/thymeleaf-extras-springsecurity4/3.0.2.RELEASE/thymeleaf-extras-springsecurity4-3.0.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/security/spring-security-core/4.0.0.RELEASE/spring-security-core-4.0.0.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-aop/4.1.6.RELEASE/spring-aop-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-beans/4.1.6.RELEASE/spring-beans-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-core/4.1.6.RELEASE/spring-core-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-context/4.1.6.RELEASE/spring-context-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-expression/4.1.6.RELEASE/spring-expression-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/security/spring-security-web/4.0.0.RELEASE/spring-security-web-4.0.0.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-web/4.1.6.RELEASE/spring-web-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/security/spring-security-config/4.0.0.RELEASE/spring-security-config-4.0.0.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/security/spring-security-acl/4.0.0.RELEASE/spring-security-acl-4.0.0.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-jdbc/4.1.6.RELEASE/spring-jdbc-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-tx/4.1.6.RELEASE/spring-tx-4.1.6.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.2.RELEASE/spring-boot-starter-web-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.2.RELEASE/spring-boot-starter-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot/1.5.2.RELEASE/spring-boot-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.2.RELEASE/spring-boot-autoconfigure-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.2.RELEASE/spring-boot-starter-logging-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar, file:/C:/Users/nabil/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar, file:/C:/Users/nabil/.m2/repository/org/slf4j/slf4j-api/1.7.24/slf4j-api-1.7.24.jar, file:/C:/Users/nabil/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.24/jcl-over-slf4j-1.7.24.jar, file:/C:/Users/nabil/.m2/repository/org/slf4j/jul-to-slf4j/1.7.24/jul-to-slf4j-1.7.24.jar, file:/C:/Users/nabil/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.24/log4j-over-slf4j-1.7.24.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-core/4.3.7.RELEASE/spring-core-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.5.2.RELEASE/spring-boot-starter-tomcat-1.5.2.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.11/tomcat-embed-core-8.5.11.jar, file:/C:/Users/nabil/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.5.11/tomcat-embed-el-8.5.11.jar, file:/C:/Users/nabil/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.11/tomcat-embed-websocket-8.5.11.jar, file:/C:/Users/nabil/.m2/repository/org/hibernate/hibernate-validator/5.3.4.Final/hibernate-validator-5.3.4.Final.jar, file:/C:/Users/nabil/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, file:/C:/Users/nabil/.m2/repository/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar, file:/C:/Users/nabil/.m2/repository/com/fasterxml/classmate/1.3.3/classmate-1.3.3.jar, file:/C:/Users/nabil/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.7/jackson-databind-2.8.7.jar, file:/C:/Users/nabil/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar, file:/C:/Users/nabil/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-web/4.3.7.RELEASE/spring-web-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-aop/4.3.7.RELEASE/spring-aop-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-beans/4.3.7.RELEASE/spring-beans-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-context/4.3.7.RELEASE/spring-context-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-webmvc/4.3.7.RELEASE/spring-webmvc-4.3.7.RELEASE.jar, file:/C:/Users/nabil/.m2/repository/org/springframework/spring-expression/4.3.7.RELEASE/spring-expression-4.3.7.RELEASE.jar, file:/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.1/lib/idea_rt.jar]
12:51:10.780 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.IllegalAccessError: tried to access method org.springframework.core.convert.support.DefaultConversionService.addCollectionConverters(Lorg/springframework/core/convert/converter/ConverterRegistry;)V from class org.springframework.boot.bind.RelaxedConversionService
at org.springframework.boot.bind.RelaxedConversionService.<init>(RelaxedConversionService.java:52)
at org.springframework.boot.bind.RelaxedDataBinder.modifyProperties(RelaxedDataBinder.java:148)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:128)
at org.springframework.validation.DataBinder.bind(DataBinder.java:630)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:272)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:235)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:186)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:171)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:157)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at SpringBootWebApplication.main(SpringBootWebApplication.java:14)
SampleController:
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
#Controller
#EnableAutoConfiguration
public class SampleController
{
#RequestMapping("/")
#ResponseBody
String home()
{
return "Hello World!";
}
public static void main(String[] args) throws Exception
{
SpringApplication.run(SampleController.class, args);
}
}
pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>BootExample</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
I've also tried adding an exclusion to the slf4j:
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
But it didn't work either. Tried solutions mentioned here but the problem remains. Any recommendation?

Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

When I compile my spring project, I got the following error.
Error creating bean with name 'entityManagerFactory' defined in class
path resource
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]:
Invocation of init method failed
I am using STS Eclipse and MySql Database
My Connection string in Application.Properties is
spring.datasource.url=jdbc:mysql://localhost:3306/stgdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
The detailed error is given below
=================================================
2016-10-15 15:34:38.875[0;39m [31mERROR[0;39m [35m3700[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at com.s2g.testrestapplication.TestRestApplication.main(TestRestApplication.java:10) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to obtain JDBC Connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:65) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcDatabaseMetaData(ExtractionContextImpl.java:75) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.locateTableInNamespace(InformationExtractorJdbcDatabaseMetaDataImpl.java:339) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:241) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
... 22 common frames omitted
Caused by: com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46) ~[transactions-jdbc-3.9.3.jar:na]
at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90) ~[transactions-jdbc-3.9.3.jar:na]
at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85) ~[transactions-jdbc-3.9.3.jar:na]
at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:347) ~[transactions-jdbc-3.9.3.jar:na]
at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:394) ~[transactions-jdbc-3.9.3.jar:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:62) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
... 33 common frames omitted
==============================
Pom.xml file
<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.s2g.testrestapplication</groupId>
<artifactId>testrestapplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestRestApplication</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-saml-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I would start by adding the following dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
and
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
UPDATE: Or simply add the following dependency.
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
People using Java 9 include this dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Adding dependencies didn't fix the issue at my end.
The issue was happening at my end because of "additional" fields that are part of the "#Entity" class and don't exist in the database.
I removed the additional fields from the #Entity class and it worked.
Goodluck.
I've jdk-12.0.2.jdk, 've found solution to the problem, add dependencies to pom.xml:
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.25.0-GA</version>
</dependency>
I suspect that the jar files of hibernate-core and hibernate-entitymanager dependencies are corrupted or were not installed properly on your machine.
I suggest that you just delete the folders named hibernate-core and hibernate-entitymanager from your Maven local repository and Maven will reinstall them.
The default location for Maven local repository is C:\Documents and Settings\[USERNAME]\.m2 in windows or ~/.m2 in Linux/Mac.
In my case, deleting any of the below annotations cause the error message 'entityManagerFactory' to show, for example.
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
or
#ManyToMany(targetEntity=listOfObject_x.class)
The error message disappears after adding the missing annotation(s).
package mypackage_unameit;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Data;
#Data
#Entity
public class Someclasss {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
#NotNull
#Size(min=5, message="Name must be at least 5 characters long")
private String name;
private Date createdAt;
#ManyToMany(targetEntity=listOfObject_x.class)
#Size(min=1, message="You must choose at least 1 ingredient")
private List<listOfObject_x> = new ArrayList<>();
#PrePersist
void createdAt() {
this.createdAt = new Date();
}
}
I solved mine by updating spring dependencies versions from 2.0.4 to 2.1.6
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
For those who are not using JPA and instead prefer to exclude the entityManagerFactory and use Spring Data JDBC or Spring JDBC can exclude the bean to avoid the exception
#SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})
For those who use Gradle instead of Maven, add this to the dependencies in your build file:
compile('javax.xml.bind:jaxb-api:2.3.0')
For my case it was due to Intellij IDEA by default set Java 11 as default project SDK, but project was implemented in Java 8.
I've changed "Project SDK" in File -> Project Structure -> Project (in Project Settings)
This error may be also related to the fact that you have an error in your "spring.datasource.url" when you gave a wrong db name for example
When we map a column, we have to pay attention to the name of the opposite column that is being mapped, for example:
/*users*/
#OneToMany(mappedBy = "partModel")
private List<UsersModel> usersModels;
/*parts*/
#ManyToOne
private PartModel partModel;
Check out postModel here.***
Adding dependencies didn't fix the issue at my end as well.
The issue was happening at my end because database myapplication in
spring.datasource.url=jdbc:mysql://localhost:3306/myapplication didn't exist in mysql.
I created the db manually, restarted the application and it worked.
I was able to fix the problem by changing the maximum-pool size value from one to two
spring.datasource.hikari.maximum-pool-size=2
Try to annotate the class with #EnableTransactionManagement. I was facing the same issue and it got resolved by adding this.
#EnableTransactionManagement
public class ConfigurationBean {
}
If you use JDK 1.8.0_201 or latest try it with older JDK.
I have same issue with JDK1.8.0_201, however it works with JDK1.8.0_101 without any code change.
I resolved this issue by Adding implements Serializable in the Model.
#Entity
#Table(name="Model_Rest")
#IdClass(Model_Rest.class)
public class Model_Rest implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
//#GeneratedValue(strategy = GenerationType.AUTO)
//#Column(columnDefinition="id")
#Id
private String login;
#Id
private String password;
#Autowired
public String getLogin() {
return login;
}
#Autowired
public void setLogin(String login) {
this.login = login;
}
#Autowired
public String getPassword() {
return password;
}
#Autowired
public void setPassword(String password) {
this.password = password;
}
public Model_Rest() {
// TODO Auto-generated constructor stub
}
public Model_Rest(String login, String password) {
this.login = login;
this.password = password;
}
#Override
public String toString() {
return "Model_Rest [login=" + login + ", password=" + password + "]";
}
}
For me, it was a result of another error
org.postgresql.util.PSQLException: FATAL: password authentication failed for user
Which means you just need to review your authentication credentials
I had the same issue on my Eclipse Luna.
I figure out that I am using JDK12 and Java 1.8. I changed JDK to JDK8 and the problem was solved.
If you want to check your JDK in Eclipse go to
Window-> Preferences-> Java- >Installed JREs
and check if they are compatible with your project.
Good luck!
For me it was the name of the database on application.properties. When I provided the correct name it worked ok.
Whoever still having the same issue. Please add the following line in application.properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
## I am using Mysql8 so I have declared MySQL8Dialect if you have other versions just add ## that version number
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
In my case the issue was multiparted and related to AWS:
as #Tareq Islam pointed out setting the dialect in application.properties helped. I used for MySQL 5.6:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect
the second issue after this was that the JDBC was not able to connect to the server due to change in SSL connection encryption. I fixed it with help of
SSLHandShakeException No Appropriate Protocol
But I needed to enable TLS1.0 by setting to /etc/java-11-openjdk/security/java.security
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL
In my case i add the following line in application.properties
,the issue was in Oracle 11g DB Driver
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
You can try to change the MySql Dialect.
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
Or
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
pom dependency:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
use #Id .Worked for me.Otherwise it i will throw error.It depends on is there anything missing in your entity class or repository
My error was solved after adding this dependency.
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.16.Final</version>
</dependency>
Try changing spring version. I had the same issue and that worked for me
I resolved mine by defining reverse-relationship annotation for an additional field
In my case I got this error when trying to make Proguard + Spring Boot 2 work.
Adding -dontusemixedcaseclassnames to proguard.conf fixes it.
In our case, we had some extra lines in the .properties file which was not needed with the new image.
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
Obviously with didn't had that Entity what it tried to load.

Categories