Spring boot + Envers ClassNotFoundException - java

I'm trying to wire in Hibernate Envers into my Spring Boot app, and I get this exception:
I've tried a lot of different dependencies for Envers, because this seems like dependency conflict issue, but nothing helped.
When I start the app, everything is ok, but when I try to annotate class with #Audited this exception drops.
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/engine/spi/SharedSessionContractImplementor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.base.BaseApplication.main(BaseApplication.java:11) [main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.3.0.RELEASE.jar:1.3.0.RELEASE]
Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/spi/SharedSessionContractImplementor
at org.hibernate.envers.boot.internal.EnversIntegrator.integrate(EnversIntegrator.java:94) ~[hibernate-envers-5.2.8.Final.jar:5.2.8.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.spi.SharedSessionContractImplementor
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
... 31 common frames omitted
My application.properties
spring.profiles.active = dev
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = true
logging.level.org.hibernate.type.descriptor.sql=trace
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect
spring.jpa.database-platform = org.hibernate.spatial.dialect.mysql.MySQLSpatial56Dialect
spring.datasource.url = jdbc:mysql://localhost:3306/database
# Username and secret
spring.datasource.username = root
spring.datasource.password = root
server.port=8082
Gradle build file:
plugins {
id 'org.springframework.boot' version '1.5.2.RELEASE'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
jar {
baseName = 'Base'
version = '0.0.1-SNAPSHOT'
}
bootRun {
systemProperties = System.properties
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version:'1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '1.3.0.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.40'
compile group: 'org.modelmapper', name: 'modelmapper', version:'0.7.5'
compile group: 'com.vividsolutions', name: 'jts', version:'1.13'
compile group: 'com.bedatadriven', name: 'jackson-datatype-jts', version:'2.3'
compile group: 'org.hibernate', name: 'hibernate-spatial', version:'5.0.11.Final'
compile group: 'org.flywaydb', name: 'flyway-core', version:'3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.4'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '8.5.6'
compile group: 'io.springfox', name: 'springfox-swagger2', version:'2.4.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.4.0'
compile group: 'org.hibernate', name: 'hibernate-envers'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.4.2.RELEASE'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}

I had the same problem, I solved adding the hibernate-core dependency, this dependency has the missing class (SharedSessionContractImplementor), so you can add it to your gradle file.
I used the hibernate-core 5.0.11.final for spring-boot 1.4.2.RELEASE
Gradle:
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.0.11.Final'

In my case the solution is to use spring-data-envers instead of the original hibernate-envers
implementation 'org.springframework.data:spring-data-envers'

Related

How to fix java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONException error?

I am getting following error when I run my spring boot service in production as windows service. Service exe is created by Jar2exe.
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mindbodyApplication': Unsatisfied dependency expressed through field 'mindBodyClientService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mindBodyClientServiceImpl': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#18769467]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.rossmoor.mindbody.MindbodyApplication.main(MindbodyApplication.java:43)
... 8 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mindBodyClientServiceImpl': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#18769467]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656)
... 28 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.rossmoor.mindbody.services.web.MindBodyClientServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#18769467]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
... 40 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/configurationprocessor/json/JSONException
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 42 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 46 more
Strange thing is it runs properly when I run it through Intellij Idea on production machine.
Both service exe and code in Intellij Idea work properly on my development machine.
Here is my build.gradle file :
plugins {
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
// // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'
// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.6.9.Final'
// https://mvnrepository.com/artifact/antlr/antlr
implementation group: 'antlr', name: 'antlr', version: '2.7.7'
// https://mvnrepository.com/artifact/com.fasterxml/classmate
implementation group: 'com.fasterxml', name: 'classmate', version: '1.5.1'
// https://mvnrepository.com/artifact/javax.activation/javax.activation-api
implementation group: 'javax.activation', name: 'javax.activation-api', version: '1.2.0'
// https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api
implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
// https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.12'
// https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.0'
// https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations
implementation group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '6.0.2.Final'
// https://mvnrepository.com/artifact/org.jboss/jandex
implementation group: 'org.jboss', name: 'jandex', version: '2.4.3.Final'
// https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging
implementation group: 'org.jboss.logging', name: 'jboss-logging', version: '3.5.0.Final'
// https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec
implementation group: 'org.jboss.spec.javax.transaction', name: 'jboss-transaction-api_1.2_spec', version: '1.1.1.Final'
implementation files('lib/connection-manager-2.0.0.1.jar')
implementation files('lib/Utils-2.0.0.1.jar')
implementation files('lib/TinyLog-2.0.0.1.jar')
}
tasks.named('test') {
useJUnitPlatform()
}
Starting with SpringBoot 2.4 the dependency
org.springframework.boot:spring-boot-configuration-processor
is no longer contained in the resulting fat-jar (Spring Boot 2.4 Release Notes).
Jar Optimizations
When generating runnable Spring Boot jars, empty starter dependencies will now be automatically removed. Since most starters only provide transitive dependencies, there is little point in packaging them in the final jar.
Spring Boot annotation processors are also removed as well as they are only useful during the build. These are spring-boot-autoconfigure-processor and spring-boot-configuration-processor.
If the exception is thrown in you own code, check that you are not using
org.springframework.boot.configurationprocessor.json.JSONException
org.springframework.boot.configurationprocessor.json.JSONObject
If you are using those, replace them, e.g.:
org.json.JSONException
org.json.JSONObject
You might need to include the related dependency:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>
The class that your mindBodyClientServiceImpl is using (indirectly) is org.springframework.boot.configurationprocessor.json.JSONException.
This comes from your build.gradle:
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
Since you have declared as compileOnly here:
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
but apparently the JSONException is used at run time, it makes your app fail when packaging with Jar2exe. The solution to this could be to include the whole dependency like so:
implementation 'org.springframework.boot:spring-boot-configuration-processor'
Just a blind guess, but probably your application could fail again, but this time at least you can see the JSONException and fix the underlying issue.

Spring Boot application run fails, even after rolling back to last successful build commit

This is my first question here, so please be kind...
I have a SpringBoot REST API running with gradle.
I recently added a new dependency in my build.gradle (implementation group: 'com.smsfactor', name: 'smsfactor', version: '1.0'), made some code, and when I tried to run the app, I had this error :
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi
Quite surprising because I didn't make any new use of the lombok library. First thing I did was adding a mapstruct dependency to my build.gradle. I also tried to define a version (1.18.20, same as on my Eclipse install) for my lombok dependency, which wasn't set before.
Both actions independently solved the issue, but created another one :
2021-04-29 12:36:51.104 ERROR 4971 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.configuration.ModelsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#21213b92]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.8.RELEASE.jar:na]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:100) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:na]
at com.feudjey.picsession.PicSessionApplication.main(PicSessionApplication.java:11) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at spring.boot.devtools#2.4.5/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:na]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466) ~[na:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.8.RELEASE.jar:na]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 30 common frames omitted
2021-04-29 12:36:51.120 WARN 4971 --- [ restartedMain] o.s.boot.SpringApplication : Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.configuration.ModelsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#21213b92]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.8.RELEASE.jar:na]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:620) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1243) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:880) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:868) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:855) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:806) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:325) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:na]
at com.feudjey.picsession.PicSessionApplication.main(PicSessionApplication.java:11) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at spring.boot.devtools#2.4.5/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:na]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466) ~[na:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.8.RELEASE.jar:na]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 30 common frames omitted
The thing is that I have "com.fasterxml:classmate:1.5.1" in my project when I run gradle dependencies. I found many threads about this dependency, but usualy users did not have included it in their project, which isn't my case.
The other weird thing is that when I stash my changes to go back to my last good build state, I encounter the same first error about lombok.
I started coding in java 4 years ago, I always find a solution to my issue in this community forums, but today I am totally lost, that's why I am writing my first thread.
Here is my build.gradle :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:'2.4.5'"
}
}
plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'eclipse'
id 'java'
id 'war'
}
bootWar {
archiveName 'rest-api.war'
}
group = 'com.feudjey'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
// Security
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.4.3'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
// Swagger
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
// File management
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation group: 'org.imgscalr', name: 'imgscalr-lib', version: '4.2'
implementation group: 'com.drewnoakes', name: 'metadata-extractor', version: '2.14.0'
// Validation
implementation group: 'org.hibernate', name: 'hibernate-validator-annotation-processor', version: '7.0.1.Final'
implementation group: 'org.hibernate.validator', name: 'hibernate-validator', version: '7.0.1.Final'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
implementation group: 'org.glassfish', name: 'javax.el', version: '3.0.0'
// Misc
implementation group: 'com.google.api-client', name: 'google-api-client', version: '1.30.10'
// Mapper
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.4.2'
// Faker
implementation group: 'com.github.javafaker', name: 'javafaker', version: '1.0.2'
// eMail
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.4.2'
// SMS
implementation group: 'com.smsfactor', name: 'smsfactor', version: '1.0'
// Paypal
implementation group: 'com.paypal.sdk', name: 'rest-api-sdk', version: '1.14.0'
// Persistance
implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
// Database
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: '42.2.20'
// Dev Tools
developmentOnly group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.4.5'
// Lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
// Tests
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
javac 11.0.10
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9)
OpenJDK 64-Bit Server VM (build 11.0.10+9, mixed mode)
Edit :
When I remove these two dependencies (and the code using them)
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'com.fasterxml.jackson.core:jackson-databind', version: '2.9.6'
I get get the following error :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repository in com.feudjey.picsession.services.ServiceBase required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Does this make any sense ?
Here is my configuration class :
package com.feudjey.picsession.configuration;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.modelmapper.ModelMapper;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import com.feudjey.picsession.contracts.GlobalContract;
#Configuration
#EnableJpaAuditing(dateTimeProviderRef = "auditingDateTimeProvider")
#EnableJpaRepositories(basePackages = {GlobalContract.BASE_PACKAGE + ".repositories"})
#EntityScan(basePackages = {GlobalContract.BASE_PACKAGE + ".entities"})
#ComponentScan(basePackages = {
GlobalContract.BASE_PACKAGE + ".events",
GlobalContract.BASE_PACKAGE + ".services",
GlobalContract.BASE_PACKAGE + ".mappers",
GlobalContract.BASE_PACKAGE + ".fixtures"})
public class ApplicationConfig {
#Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
// #Bean
// public Docket api() {
// return new Docket(DocumentationType.SWAGGER_2)
// .select()
// .apis(RequestHandlerSelectors.basePackage(GlobalContract.BASE_PACKAGE + ".controllers"))
// .paths(PathSelectors.any())
// .build();
// }
#Bean
public DateTimeProvider auditingDateTimeProvider() {
return () -> Optional.of(OffsetDateTime.now());
}
#Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final String origin = "*";
final String header = "*";
final String method = "*";
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin(origin);
config.addAllowedHeader(header);
config.addAllowedMethod(method);
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
#Bean
public ApplicationEventMulticaster applicationEventMulticaster() {
final SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
return eventMulticaster;
}
}
Edit 2 :
OK, I've just noticed that the project runs perfectly whith gradle bootrun, but doesn't with eclipse, so I have no debug mode.
I do a gradle cleaneclipse eclipse before every eclipse build, so what can it be ?
Please ask me if you want more details about my project. Hope someone can help me.
Thanks.

Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL

Caused by:
java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
group 'batch'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'
bootRun {
addResources = true
}
war {
baseName = 'Batch'
version = '0.1.0'
manifest {
attributes 'Main-Class': 'com.Application'
}
}
jar {
manifest {
attributes 'Main-Class': 'src.main.java.com.Application'
}
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.6.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.24'
compile group: 'org.json', name: 'json', version: '20180130'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.6.RELEASE'
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '7.0.82'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.2.4.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.7.4.RELEASE'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.1'
}
Technologies used:
Gradle, Springboot,jdk7
Exception Trace:
tionConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh att
empt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/aut
oconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persist
ence unit root URL
2018-05-14 21:11:04.427 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2018-05-14 21:11:04.505 INFO 3136 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report enable debug logging (start with --debug)
2018-05-14 21:11:04.552 ERROR 3136 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfi
gure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence u
nit root URL
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.3.2.RELEAS
E.jar!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.2.RELEASE.j
ar!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar
!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.R
ELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.2.RELEASE.ja
r!/:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEA
SE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
at com.Application.main(Application.java:15) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [Batch-0.1.0.war:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [Batch-0.1.0.war:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [Batch-0.1.0.war:na]
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59) [Batch-0.1.0.war:na]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:603) ~[spring-orm
-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443) ~[spring-orm-4.3.2.RELE
ASE.jar!/:4.3.2.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424) ~[spring-orm-4.3.2.RELEASE.jar!/
:4.3.2.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310) ~[spring-orm-4.3
.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.2.RELEASE.ja
r!/:4.3.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.REL
EASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.2.REL
EASE.jar!/:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.2.RELEAS
E.jar!/:4.3.2.RELEASE]
... 24 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) ~[spring-core-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:600) ~[spring-orm
-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
... 31 common frames omitted
Solution:
Removed
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.1'
Added a class like below
#Entity
public class TestEntity {
#Id
#GeneratedValue
private int id;
}

Spring-Boot cannot run in Eclipse and not recognize autowired DataSource [duplicate]

This question already has answers here:
Spring Boot auto configuration for datasource
(2 answers)
Closed 4 years ago.
I'm trying to run simple API server under control of Spring-boot and have 2 problems:
1. In Eclipse (Neon.1 Release (4.6.1)) when I try to launch application I get an error about servlet container (watch errors at the end of topic).
2. When I run gradle build and try to run jar I see error about not set DataSource bean.
UPDATE: Issue 1 not a big deal, cause other person was able to run project from IDEA perfectly fine and smooth (and it worked). Which is interesting, cause in any case, jar builded by gradle give error listed at the end of topic, about missed datasource, even if you move DataSource from main to #Configuration class. Which mean, that I have problem in Eclipse (my local problem) AND problem with gradle build task.
UPDATE 2: Issue resolved by Spring Boot auto configuration for datasource Still I have no idea why dataSource wasn't able to autowire, but this way even better, cause using approach from link I can get values from properties and switch them using different environments. Thanks all for help.
My code followed:
Application.java:
package com.my.package;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.AbstractApplicationContext;
import com.my.package.MvcConfig;
#SpringBootApplication
#EnableAutoConfiguration
#ComponentScan
public class Application {
#Autowired
DataSource dataSource;
#SuppressWarnings({ "unused", "resource" })
public static void main(String[] args) {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(MvcConfig.class);
SpringApplication.run(Application.class, args);
}
}
MvcConfig.java:
package com.my.package;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
#Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
Application.properties:
# ===============================
# = DATA SOURCE
# ===============================
spring.datasource.url = jdbc:mysql://localhost:3306/benchmark
spring.datasource.username = root
spring.datasource.password =root
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = false
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Build.gradle:
plugins {
id "org.springframework.boot" version "1.5.6.RELEASE"
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.5.6.RELEASE'
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version:'1.5.6.RELEASE') {
exclude(module: 'spring-boot-starter-tomcat')
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty', version:'1.5.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version:'1.5.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.5.6.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.6'
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.1'
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.11.RELEASE') {
exclude(module: 'commons-logging')
}
compile group: 'org.springframework', name: 'spring-jdbc', version:'4.3.8.RELEASE'
compile group: 'javax.interceptor', name: 'javax.interceptor-api', version:'1.+'
testCompile group: 'junit', name: 'junit', version:'4.11'
}
And here is errors. When I'm trying to launch in eclipse:
12:40:08.155:WARN [main]: o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext -
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;
12:40:08.164:INFO [main]: o.s.b.a.l.AutoConfigurationReportLoggingInitializer -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
12:40:08.169:ERROR[main]: o.s.boot.SpringApplication -
Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
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.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.my.package.Application.main(Application.java:26)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;
at org.springframework.boot.web.servlet.ServletRegistrationBean.onStartup(ServletRegistrationBean.java:191)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:229)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:89)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:213)
at org.springframework.boot.context.embedded.jetty.ServletContextInitializerConfiguration$Initializer.callInitializers(ServletContextInitializerConfiguration.java:83)
at org.springframework.boot.context.embedded.jetty.ServletContextInitializerConfiguration$Initializer.doStart(ServletContextInitializerConfiguration.java:72)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:120)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:844)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.initialize(JettyEmbeddedServletContainer.java:104)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.<init>(JettyEmbeddedServletContainer.java:82)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.getJettyEmbeddedServletContainer(JettyEmbeddedServletContainerFactory.java:561)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.getEmbeddedServletContainer(JettyEmbeddedServletContainerFactory.java:190)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
... 8 common frames omitted
When I run jar:
12:43:24.707:DEBUG[main]: o.s.b.d.LoggingFailureAnalysisReporter -
Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
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.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.my.package.Application.main(Application.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
12:43:24.707:ERROR[main]: o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because #ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because #ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans
I've tried to play with dependencies, with annotations in application.java, but wasn't able to run this. I was thinking about this problem local, but I'm not sure where to look (I was reinstalling Gradle to 3.5 version not way back ago).
Spring beans can't be Autowired in the main Application class out of box. You should move it down to the components like services/controllers etc.
Issue resolved by Spring Boot auto configuration for datasource . Still I have no idea why dataSource wasn't able to autowire, but this way even better, cause using approach from link I can get values from properties and switch them using different environments. Thanks all for help.

Spring AWS SQS NoSuchMethodFound Exception

I am using Spring Integration SQS Outbound Channel Adapter to publish payload to SQS. I am running into some dependency issue. I am getting the exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.aws.outbound.SqsMessageHandler#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.aws.outbound.SqsMessageHandler]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.expedia.dataloader.boot.Application.main(Application.java:15)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.aws.outbound.SqsMessageHandler]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
... 17 more
Caused by: java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.integration.aws.outbound.SqsMessageHandler.<init>(SqsMessageHandler.java:56)
at org.springframework.integration.aws.outbound.SqsMessageHandler.<init>(SqsMessageHandler.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessoava:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 19 more
Here are my Gradle dependencies:
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
compile 'org.springframework.cloud:spring-cloud-aws-context:1.2.2.RELEASE'
compile 'org.springframework.cloud:spring-cloud-aws-core:1.2.2.RELEASE'
compile ("org.springframework.cloud:spring-cloud-aws-messaging:1.2.2.RELEASE") {
exclude group:'com.amazonaws', module:'aws-java-sdk-sqs'
}
compile 'org.apache.commons:commons-lang3:3.+'
compile "org.springframework:spring-context:4.3.8.RELEASE"
compile "org.springframework:spring-webmvc:4.3.8.RELEASE"
compile "org.springframework:spring-aop:4.3.8.RELEASE"
compile "org.aspectj:aspectjweaver:1.8.2"
compile 'org.codehaus.castor:castor:1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'
compile 'org.springframework.integration:spring-integration-core:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-http:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-xml:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-amqp:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-stream:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-file:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-java-dsl:1.0.0.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-aws', version: '1.0.0.RELEASE'
compile 'org.projectlombok:lombok:1.14.8'
compile 'joda-time:joda-time:2.+'
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: 'org.hibernate'
exclude group: 'org.springframework'
exclude group: 'com.fasterxml.jackson.core'
exclude group: 'org.mockito'
exclude group: 'junit'
}
compile "ch.qos.logback:logback-classic:1.1.2"
compile "org.slf4j:jcl-over-slf4j:1.7.7"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile 'org.apache.httpcomponents:httpclient:4.3.6'
compile 'org.apache.httpcomponents:httpmime:4.3.6'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'
testCompile 'junit:junit:4.+'
testCompile 'org.springframework:spring-test:4.3.8.RELEASE'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.apache.commons:commons-io:1.3.2'
jaxb group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.6'
jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: '2.2.6'
jaxb group: 'javax.xml', name: 'jaxb-api', version: '2.1.5'
}
Here is my SQS config:
<aws-messaging:sqs-async-client id="sqs"/>
<int-aws:sqs-outbound-channel-adapter channel="sqsChannel" sqs="sqs" queue="${sqs.queue}"/>
I have tried all suggestions that I found on Internet, still no luck. Can someone please help?
According to Artem Bilan, modify the following:
SI AWS to 1.1.0
SC-AWS to 1.2.2
SC-AWS fetches AWS SDK version 1.11.125. I had to override AWS SQS SDK version to be 1.11.209 as mentioned here to fix the dependencies issues.

Categories