Spring Boot and Hibernate 5 - spring-boot

I am very new to Spring Boot. I am trying to add Hibernate 5 to my Spring Boot project and make it to work.
My config class:
import org.apache.commons.dbcp.BasicDataSource;
import org.hibernate.SessionFactory;
...
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#EnableTransactionManagement
#ComponentScan(value = { "boot.entities" })
#PropertySources(value = { #PropertySource(value = { "classpath:db- connection.properties", "hibernate.properties" }) })
public class Config {
#Bean
public DataSource getDataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setUrl(env.getProperty("db.connection.url"));
...
return ds;
}
#Bean
#Autowired
public LocalSessionFactoryBean getSessionFactory(DataSource dataSource) {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
...
sessionFactory.setHibernateProperties(hibernateProperties);
return sessionFactory;
}
#Bean
#Autowired
public HibernateTransactionManager geTransactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
return transactionManager;
}
}
my build.gradle file:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
...
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
// runtime('com.h2database:h2')
// ### hibernate 5
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.4.Final'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.2'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
compile group: 'org.javassist', name: 'javassist', version: '3.21.0-GA'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
and the error trying to start:
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 java.lang.NoClassDefFoundError: org/hibernate/boot/MetadataBuilder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at boot.config.DemoApplication.main(DemoApplication.java:10) [bin/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.4.2.RELEASE.jar:1.4.2.RELEASE]
Caused by: java.lang.NoClassDefFoundError: org/hibernate/boot/MetadataBuilder
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.MetadataBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_51]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_51]
... 27 common frames omitted
I thank you in advance for the help! And sorry for my english!

Related

Class not found exception in Spring boot application deployment to external tomcat

I have recently upgraded spring boot application from 1.3.1 to 1.5.10 version and Gradle from 2.7 to 3.5. I have fixed all the errors regarding upgrade and is working fine with IDE (STS). But when I am trying to deploy the war to external tomcat getting java.lang.NoClassDefFoundError: org/junit/rules/TestRule.
The application was working fine with old configuration only updated spring boot and Gradle version.
[ERROR] org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.projectx.SpringIntegrationApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
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.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
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.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/junit/rules/TestRule
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2270)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 31 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.junit.rules.TestRule
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 42 common frames omitted
22-Jan-2020 12:35:33.963 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.projectx.SpringIntegrationApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
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.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
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.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 26 more
Caused by: java.lang.NoClassDefFoundError: org/junit/rules/TestRule
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2270)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 31 more
Caused by: java.lang.ClassNotFoundException: org.junit.rules.TestRule
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 42 more
22-Jan-2020 12:35:33.965 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /usr/local/apache-tomcat-8.5.5/webapps/ROOT.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:728)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Gradle
buildscript {
ext {
// springBootVersion = '1.3.0.RELEASE'
springBootVersion = '1.5.10.RELEASE'
googleAPIClientVersion='1.2.3-alpha'
googleAPIClientJacksonVersion='1.23.0'
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath ('org.asciidoctor:asciidoctor-gradle-plugin:1.5.2')
//classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
//apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'org.asciidoctor.convert'
war {
baseName = 'ROOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile('org.springframework.integration:spring-integration-twitter:4.0.0.RELEASE')
compile('org.springframework.integration:spring-integration-java-dsl:1.0.0.RELEASE')
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile('org.springframework.boot:spring-boot-starter-security')
compile("mysql:mysql-connector-java:5.1.6")
compile('com.google.code.gson:gson:2.3')
compile('javax.interceptor:javax.interceptor-api:1.2')
compile('com.sun.mail:javax.mail:1.5.5')
compile('com.itextpdf:itextpdf:5.4.5')
compile('com.itextpdf.tool:xmlworker:5.5.6')
//excel sheet
compile ('org.apache.commons:commons-lang3:3.6')
compile ('org.dstadler:commons-dost:1.0.0.23')
compile ('com.google.guava:guava:21.0')
compile ('org.apache.commons:commons-csv:1.5')
compile 'org.apache.poi:poi:3.17'
compile 'org.apache.poi:poi-ooxml:3.17'
compile 'org.apache.poi:poi-scratchpad:3.17'
testCompile("com.jayway.jsonpath:json-path:1.1.0")
// testCompile('org.springframework.boot:spring-boot-starter-test')
// testCompile("org.mockito:mockito-core:1.+")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.restdocs:spring-restdocs-mockmvc:1.1.1.RELEASE")
//compile('com.amazonaws:aws-java-sdk-s3:1.10.75')
//Deploy on same tomcat with diffrent domain dependancy
compile group: 'org.springframework.integration', name: 'spring-integration-jmx', version: '4.3.0.RELEASE'
//JJWT
compile ('io.jsonwebtoken:jjwt:0.6.0')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
//AWS S3 SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.86'
//AWS SES SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-ses', version: '1.11.86'
//AWS SSM SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-ssm', version: '1.11.665'
//AWS EC2
compile group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.665'
//SafetyNet
//compile group: 'com.google.api.client', name: 'google-api-client-json', version: googleAPIClientVersion
compile group: 'com.google.http-client', name: 'google-http-client-jackson2', version: googleAPIClientJacksonVersion
// https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter
compile group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '1.9'
//Firebase
compile group: 'com.google.firebase', name: 'firebase-admin', version: '5.2.0'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('com.google.maps:google-maps-services:0.9.1')
// https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-ip
compile group: 'org.springframework.integration', name: 'spring-integration-ip', version: '4.3.0.RELEASE'
compile('org.flywaydb:flyway-core')
//mysql connection pooling
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.4.6'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
ext {
snippetsDir = file('build/generated-snippets')
}
test {
outputs.dir snippetsDir
}
asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
dependsOn test
}
Guide me to diagnose this issue. Also want to know why tomcat loading junit class at run time.
Your suggestions will be highly appreciable.
Solved by adding compile time dependency for junit. I am unclrear why spring boot 1.5 need Junit dependency at runtime, If any know please explain it.

flyway with spring boot and gradle--org.flywaydb.core.Flyway: method <init>()V not found

I have a spring boot project with gradle and using postgres db. I want to test by using flyway for database migrations. I am facing below error. My build.gradle and application.properties are also given below. Please help me with this error. I believe this is something to do with set up but not the actual code.
Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123) ~[spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:300) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1082) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1071) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at com.ford.mach1mldb.AccessingDataRestApplication.main(AccessingDataRestApplication.java:10) [main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
... 20 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.flywaydb.core.Flyway: method <init>()V not found
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$SpringBootFlyway.<init>(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$SpringBootFlyway.<init>(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:130) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9.CGLIB$flyway$0(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9$$FastClassBySpringCGLIB$$b74dfec1.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$1b5373a9.flyway(<generated>) ~[spring-boot-autoconfigure-1.5.22.RELEASE.jar:1.5.22.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_221]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_221]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_221]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
... 21 common frames omitted
Build.gradle:
buildscript {
ext {
springBootVersion = '1.5.22.RELEASE'
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
dependencies {
compile( 'org.springframework.boot:spring-boot-starter-data-rest' )
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile files('./lib/postgresql-42.2.8.jar')
compile group: 'org.flywaydb', name: 'flyway-core', version: '6.0.1'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.0.Final'
compile group: 'org.springframework.ws', name: 'spring-ws-support'
compile('org.springframework:spring-context-support')
compile "org.apache.httpcomponents:httpmime:4.2.3"
compile "org.apache.httpcomponents:httpclient:4.5.2"
compile "org.apache.httpcomponents:httpcore:4.4.5"
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
}
dependencyManagement {
imports {
mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:1.4.1.RELEASE"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.SR5"
}
}
Application.properties:
spring.jpa.show-sql=true
#postgress
spring.datasource.url=jdbc:postgresql://xxx/xxx
spring.datasource.username=xxx
spring.datasource.password=
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
flyway.baseline-on-migrate=true
Yes, I also upgrade my version of the flyway from 5.2.4 to 7.0.0 and catch the same error.
To resolve this issue I downgrade the flyway version to 6.5.0 and it works now!
Try another version of flyway (older) or remove version if it possible in Gradle (It helps for me with maven).

Gradle build failed - Spring boot project with lombok

Cannot build Spring-boot project in Gradle. I get the following error (stack):
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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:190)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appointmentController' defined in file [C:\Users\triin\Desktop\ValiIT\FinalProject\trikad_uus\build\classes\java\main\ee\bcs\valiit\trikad\controller\AppointmentController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appointmentService' defined in file [C:\Users\triin\Desktop\ValiIT\FinalProject\trikad_uus\build\classes\java\main\ee\bcs\valiit\trikad\service\AppointmentService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'ee.bcs.valiit.trikad.data.AppointmentsRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
... 49 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appointmentService' defined in file [C:\Users\triin\Desktop\ValiIT\FinalProject\trikad_uus\build\classes\java\main\ee\bcs\valiit\trikad\service\AppointmentService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'ee.bcs.valiit.trikad.data.AppointmentsRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
... 67 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'ee.bcs.valiit.trikad.data.AppointmentsRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ...
The main problem seems to be in the file AppointmentController which is as follows:
package ee.bcs.valiit.trikad.controller;
import ee.bcs.valiit.trikad.data.Appointments;
import ee.bcs.valiit.trikad.service.AppointmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
#RestController
#RequestMapping(value = "/app")
#Slf4j
public class AppointmentController {
#Autowired
private AppointmentService appointmentService;
#PostMapping("/add")
private void add(#RequestParam String event_name, #RequestParam Date time, #RequestParam String description) {
Appointments app = new Appointments();
app.setEventname(event_name);
app.setTime(time);
app.setDescription(description);
appointmentService.add(app);
}
#PostMapping(value = "/delete/{id}", produces="application/json")
private void delete(#PathVariable Long id) {
Appointments app = appointmentService.get(id);
appointmentService.delete(app);
}
}
The file AppointmentService, that the controller uses is the following:
package ee.bcs.valiit.trikad.service;
import ee.bcs.valiit.trikad.data.Appointments;
import ee.bcs.valiit.trikad.data.AppointmentsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
#Service
public class AppointmentService {
#Autowired
private AppointmentsRepository appointmentsRepository;
public List<Appointments> list() {
return appointmentsRepository.findAll();
}
public Appointments get(Long id) {
return appointmentsRepository.getOne(id);
}
public List<Appointments> findByUserId(Long id) {
return appointmentsRepository.findByUserId(id);
}
#Transactional
public void delete(Appointments appointment) {
appointmentsRepository.delete(appointment);
}
#Transactional
public void add(Appointments appointment) {
appointmentsRepository.save(appointment);
}
}
And the repository that the service uses is a simple interface:
package ee.bcs.valiit.trikad.data;
import org.springframework.data.jpa.repository.JpaRepository;
import javax.transaction.Transactional;
import java.util.List;
#Transactional
public interface AppointmentsRepository extends JpaRepository<Appointments, Long> {
List<Appointments> findByUserId(Long id);
}
Configuration is done by ApplicationContext file which (part of it) is the following:
<!-- Common. -->
<context:component-scan base-package="ee.bcs.valiit.trikad" />
<context:property-placeholder location="classpath:application.properties" file-encoding="UTF-8" />
<jpa:repositories base-package="ee.bcs.valiit.trikad.data" />
Application class
package ee.bcs.valiit.trikad;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
#ComponentScan ({"ee.bcs.valiit.trikad.data", "ee.bcs.valiit.trikad.service","ee.bcs.valiit.trikad.model", "ee.bcs.valiit.trikad.controller"})
public class TrikadApplication {
public static void main(String[] args) {
SpringApplication.run(TrikadApplication.class, args);
}
}
My build gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
ext {
springVersion = '5.0.8.RELEASE'
springDataVersion = '2.0.9.RELEASE'
hibernateVersion = '5.3.5.Final'
hibernateJpaVersion = '1.0.2.Final'
postgresqlVersion = '9.4.1212'
jacksonVersion = '2.9.6'
lombokVersion = '1.18.2'
slf4jVersion = '1.7.25'
junitVersion = '4.12'
}
}
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'ee.bcs.valiit'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework:spring-context-support:${springVersion}",
"org.springframework.data:spring-data-jpa:${springDataVersion}",
"org.springframework:spring-webmvc:${springVersion}",
"org.springframework:spring-web:${springVersion}",
"com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}",
"com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:${jacksonVersion}",
"org.springframework:spring-context-support:${springVersion}",
"org.hibernate:hibernate-entitymanager:${hibernateVersion}",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernateJpaVersion}",
"com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-dependencies', version: '2.0.4.RELEASE', ext: 'pom'
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.4.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-core', version: '5.0.7.RELEASE'
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
runtime "org.postgresql:postgresql:${postgresqlVersion}"
testCompile "junit:junit:${junitVersion}"
}
I have no idea what could be wrong. Can someone help me?

Failed to load class of driverClassName mongodb.jdbc.MongoDriver

Can someone please help me out. I am suck here for 2 days now. I am working on spring boot with access to two(2) data-sources. The application using HikariCp to connect to Postgresql and Mongodb, but I am getting the mongodb error. If I point the mongodb to another database (like Mysql or so) it will work but not with mongodb.
DataSourceOne
#Configuration
#EnableJpaRepositories(
basePackages = "com.deanace.oauth2.repository.datasourceOne",
entityManagerFactoryRef = "entityManagerFactoryBeanOne",
transactionManagerRef = "transactionManagerOne"
)
public class DataSourceOne {
#Value("${spring.datasource.one.driverClassName}")
private String driver;
#Value("${spring.datasource.one.url}")
private String url;
#Value("${spring.datasource.one.username}")
private String username;
#Value("${spring.datasource.one.password}")
private String password;
#Bean
public DataSource DataSourceOne(){
HikariConfig config = new HikariConfig();
config.setDriverClassName(driver);
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setAutoCommit(true);
return new HikariDataSource(config);
}
#Bean
public PlatformTransactionManager transactionManagerOne(){
return new JpaTransactionManager(entityManagerFactoryBeanOne().getObject());
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBeanOne() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
entityManagerFactoryBean.setDataSource(DataSourceOne());
entityManagerFactoryBean.setPackagesToScan("com.deanace.oauth2.entities");
return entityManagerFactoryBean;
}
}
DataSourceTwo
#Configuration
#EnableJpaRepositories(
basePackages = "com.deanace.oauth2.repository.datasourceTwo",
entityManagerFactoryRef = "entityManagerFactoryBeanTwo",
transactionManagerRef = "transactionManagerTwo"
)
public class DataSourceTwo {
#Value("${spring.datasource.mongodb.driverClassName}")
private String driver;
#Value("${spring.datasource.mongodb.url}")
private String url;
#Value("${spring.data.mongodb.username}")
private String username;
#Value("${spring.data.mongodb.password}")
private String password;
#Bean
public DataSource DataSourceTwo(){
HikariConfig config = new HikariConfig();
config.setDriverClassName(driver);
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setAutoCommit(true);
return new HikariDataSource(config);
}
#Bean
public PlatformTransactionManager transactionManagerTwo(){
return new JpaTransactionManager(entityManagerFactoryBeanTwo().getObject());
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBeanTwo() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
entityManagerFactoryBean.setDataSource(DataSourceTwo());
entityManagerFactoryBean.setPackagesToScan("com.deanace.oauth2.entities");
return entityManagerFactoryBean;
}
}
application.properties
spring.application.name=spring-security-oauth2
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
# suppress inspection "SpringBootApplicationProperties" for whole file
server.port=8080
# ===============================
# DATASOURCE
# ===============================
# DataSource (Postgresql offline).
spring.datasource.one.driverClassName=org.postgresql.Driver
spring.datasource.one.url=jdbc:postgresql://localhost:5432/application1
spring.datasource.one.username=postgres
spring.datasource.one.password=password
#mongodb mongodb.jdbc.MongoDriver
spring.datasource.one.driverClassName=org.MongoDriver.Driver
spring.datasource.one.url=jdbc:mongo://localhost:5432/application2
spring.data.mongodb.username=mongodb
spring.data.mongodb.password=password
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=application2
Error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactoryBeanTwo' defined in class path resource [com/deanace/oauth2/persistence/DataSourceTwo.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactoryBeanTwo' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataSourceTwo' defined in class path resource [com/deanace/oauth2/persistence/DataSourceTwo.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'DataSourceTwo' threw exception; nested exception is java.lang.RuntimeException: Failed to load class of driverClassName mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at com.deanace.oauth2.SpringSecurityOauth2Application.main(SpringSecurityOauth2Application.java:64) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactoryBeanTwo' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataSourceTwo' defined in class path resource [com/deanace/oauth2/persistence/DataSourceTwo.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'DataSourceTwo' threw exception; nested exception is java.lang.RuntimeException: Failed to load class of driverClassName mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 18 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataSourceTwo' defined in class path resource [com/deanace/oauth2/persistence/DataSourceTwo.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'DataSourceTwo' threw exception; nested exception is java.lang.RuntimeException: Failed to load class of driverClassName mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.obtainBeanInstanceFromFactory(ConfigurationClassEnhancer.java:389) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56.DataSourceTwo(<generated>) ~[classes/:na]
at com.deanace.oauth2.persistence.DataSourceTwo.entityManagerFactoryBeanTwo(DataSourceTwo.java:62) ~[classes/:na]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56.CGLIB$entityManagerFactoryBeanTwo$1(<generated>) ~[classes/:na]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56$$FastClassBySpringCGLIB$$12340b71.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56.entityManagerFactoryBeanTwo(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'DataSourceTwo' threw exception; nested exception is java.lang.RuntimeException: Failed to load class of driverClassName mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 41 common frames omitted
Caused by: java.lang.RuntimeException: Failed to load class of driverClassName mongodb.jdbc.MongoDriver
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:323) ~[HikariCP-2.5.1.jar:na]
at com.deanace.oauth2.persistence.DataSourceTwo.DataSourceTwo(DataSourceTwo.java:43) ~[classes/:na]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56.CGLIB$DataSourceTwo$0(<generated>) ~[classes/:na]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56$$FastClassBySpringCGLIB$$12340b71.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at com.deanace.oauth2.persistence.DataSourceTwo$$EnhancerBySpringCGLIB$$cf32bb56.DataSourceTwo(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 42 common frames omitted
Caused by: java.lang.ClassNotFoundException: mongodb.jdbc.MongoDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_152]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_152]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_152]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_152]
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:318) ~[HikariCP-2.5.1.jar:na]
... 53 common frames omitted
Or if anyone can help with another approach that can be of help. Thank in advance
If I understand correctly, You are trying to use mongoDB with JDBC. I think this is not a common practice use JDBC with mongoDB. However if you want to use this way,there is unityJDBC , that you can use as JDBC driver. Also take a look at this.
If you want to connect monogoDb with JDBC, you can add these two lines in application.properties file for connecting mongodb with JDBC and to exclude autoconfiguration.
#connect mongodb with jdbc
spring.data.mongodb.uri=mongodb://localhost:27017/testDb\
#exclude jdbc autoconfiguration
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Also put #EnableAutoConfiguration annotation in application's main.class
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, XADataSourceAutoConfiguration.class})
Because the JPA auto configuration feature of the spring boot application attempts to establish database connection using JPA Datasource. The java class DataSourceAutoConfiguration is responsible for loading JPA DataSource. The auto configuration can be disabled by excluding DataSourceAutoConfiguration class from the spring boot context.

Deploying Spring Boot Application to Tomcat 8

I have a Spring Boot application which works fine if I use the provided jar file. But when I try to deploy it as a war file to Tomcat 8 - it fails to work. I get the following output:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration.server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties': Could not bind properties to [unknown] (target=server, ignoreInvalidF
ields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:133)
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:124)
at org.springframework.boot.context.web.SpringB
ootServletInitializer.onStartup(SpringBootServletInitializer.java:81)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1293)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:673)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:221)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
at org
.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:
614)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunn
able.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration.server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties': Could not bind properties to [unknown] (target=server, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.spring
framework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springfra
mework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:209)
at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:85)
at org.springframework.boot.context.embedded.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:73)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:234)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:221)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(Emb
eddedWebApplicationContext.java:206)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 42 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration.server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties': Could not bind properties to [unknown] (target=server, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.
springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 67 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties': Could not bind properties to [unknown] (target=server, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:304)
at org.spring
framework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:251)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factor
y.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 69 common frames omitted
Caused by: javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1405)
at org.hibernate.validator.internal.engine.Vali
datorImpl.isValidationRequired(ValidatorImpl.java:1381)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:542)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:487)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:451)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:403)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:92)
at org.springframework.validation.DataBinder.validate(DataBinder.java:768)
at org.springframework.boot.bind.PropertiesConfigurationFactory.validate(PropertiesConfigurationFactory.java:286)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:255)
at o
rg.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:227)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:297)
... 82 common frames omitted
Caused by: java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
at javax.persistence.Persistence$1.isLoaded(Persistence.java:110)
at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56)
at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:137)
at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation.isReachable(CachingTraversableResolverForSingleValidation.java:46)
at org.hibernate.validator.internal.engine.ValidatorImpl.is
Reachable(ValidatorImpl.java:1396)
... 94 common frames omitted
2015-10-17 21:32:00.194 INFO 14049 --- [apr-8080-exec-4] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/classes/, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/validation-api-1.1.0.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/dom4j-1.6.1.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jboss-logging-3.1.3.GA.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/hibernate-core-4.3.8.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/bootstrap-3.2.0.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/tomcat-jdbc-8.0.20.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-beans-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/angularjs-1.3.8.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-context-4.1.7.RELEASE.jar, file:/var/
lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-web-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/snakeyaml-1.14.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-aspects-4.1.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-data-jpa-1.7.2.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/mysql-connector-java-5.1.13.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/aspectjweaver-1.8.5.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/angular-bootstrap-0.13.4.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/angular-route-1.4.7.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/aspectjrt-1.8.5.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-jdbc-1.2.3.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/antlr-2.7.7.jar, file:/var/lib/tomcat8/webapps/Invento
ryAccounting/WEB-INF/lib/spring-orm-4.1.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-tx-4.1.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jboss-logging-annotations-1.2.0.Beta1.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jcl-over-slf4j-1.7.12.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-core-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-actuator-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-web-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/tomcat-juli-8.0.20.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/classmate-1.0.0.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jandex-1.1.0.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-logging-1.2.6.RELEASE.jar, file:/var/lib/tomca
t8/webapps/InventoryAccounting/WEB-INF/lib/aopalliance-1.0.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/javassist-3.18.1-GA.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jackson-databind-2.4.6.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/hibernate-commons-annotations-4.0.5.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jul-to-slf4j-1.7.12.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/hibernate-validator-5.1.3.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-aop-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-aop-1.2.3.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-webmvc-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/logback-core-1.1.3.jar, file:/var/lib/to
mcat8/webapps/InventoryAccounting/WEB-INF/lib/org.json-chargebee-1.0.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jackson-core-2.4.6.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/slf4j-api-1.7.12.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jquery-1.11.1.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/javax.transaction-api-1.2.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/log4j-over-slf4j-1.7.12.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/jackson-annotations-2.4.0.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/xml-apis-1.0.b2.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-autoconfigure-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/hibernate-entitymanager-4.3.8.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-data-commons-1.9.2.RELEASE.jar, file:/var/lib/tomcat8/webap
ps/InventoryAccounting/WEB-INF/lib/spring-jdbc-4.1.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-data-jpa-1.2.3.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-actuator-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-boot-starter-1.2.6.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/spring-expression-4.1.7.RELEASE.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/logback-classic-1.1.3.jar, file:/var/lib/tomcat8/webapps/InventoryAccounting/WEB-INF/lib/angular-1.4.7.jar]
2015-10-17 21:32:00.196 ERROR 14049 --- [apr-8080-exec-4] o.s.boot.SpringApplication : Application startup failed
My setup is on Arch Linux with MariaDB (MySQL), I am using gradle as a build tool. Here is my build file:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
classpath("gradle.plugin.com.craigburke.gradle:jasmine-gradle:1.2.0")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'com.craigburke.jasmine'
jasmine {
basePath = '/'
files = [
'https://raw.githubusercontent.com/angular/code.angularjs.org/master/1.3.8/angular.min.js',
'https://raw.githubusercontent.com/angular/code.angularjs.org/master/1.3.8/angular-route.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.0/ui-bootstrap-tpls.min.js',
'https://raw.githubusercontent.com/angular/code.angularjs.org/master/1.3.8/angular-mocks.js',
'src/main/resources/static/js/*',
'src/main/resources/static/js/controllers/*',
'src/test/resources/static/js/*.spec.js',
]
additional = [
colors: true
]
}
jar {
baseName = 'InventoryAccounting'
}
war {
baseName = 'InventoryAccounting'
}
configurations {
providedRuntime
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
main {
java {
srcDir 'src/java'
}
resources {
srcDir 'src/resources'
srcDir 'src/generated-resources'
}
}
}
springBoot {
mainClass = "app.Application"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.2.3.RELEASE")
compile("mysql:mysql-connector-java:5.1.13")
compile("org.webjars:angularjs:1.3.8")
compile("org.webjars.npm:angular-route:1.4.7")
compile("org.webjars.bower:angular-bootstrap:0.13.4")
compile("org.webjars:bootstrap:3.2.0")
compile("org.json:org.json:chargebee-1.0")
testCompile("org.webjars:jasmine:2.0.0")
testCompile("org.hamcrest:hamcrest-all:1.3")
testCompile("org.springframework.boot:spring-boot-starter-test")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
And my application class looks like this:
package app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.builder.SpringApplicationBuilder;
#SpringBootApplication
#RestController
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
For me, this is the important thing in the log:
java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
But I have no idea what is causing that.
I can not seem to figure out what am I missing. Ideas?
After some tinkering I fixed the issue. It happened after I added the following to my dependencies in my gradle build file:
dependencies {
...
compile("org.eclipse.persistence:javax.persistence:2.1.0")
...
}
I figured it out according to the log that I had. Hope this helps anyone having similar issues.

Resources