Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil - spring-boot

I am using following version of corda -
buildscript {
ext.corda_release_version = '2.0.0'
ext.corda_gradle_plugins_version = '1.0.0'
I am using following version of spring boot web server -
buildscript {
ext.spring_boot_version = '1.5.7.RELEASE'
ext.spring_version = '4.3.11.RELEASE'
}
I am using following version of log4j -
dependencies {
compile "org.apache.logging.log4j:log4j-web:2.7"
Following error is thrown while compiling -
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
at net.corda.server.ServerKt.main(Server.kt:29)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.ReflectionUtil
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
Expecting insights.
Thanks in advance.

You are using a version of log4j that is conflicting with Springs own dependency on the library. Try removing your log4j dependency and rely on the one Spring is bringing in.
The log4j dep is probably a lower version than what spring wants, hence the NoClassDefFoundError.

Related

Spring Boot 1 and Gradle: ClassNotFoundException SpringApplicationBuilder

I've got a Gradle configuration for a Spring Boot 1.5 application. It runs fine in Spring Tool Suite, but gradlew build creates a jar file with no jar files in the BOOT-INF folder. This of course prevents the successful execution of the jar file:
java -jar build\libs\myapp-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.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:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/builder/SpringApplicationBuilder
at myapp.boot.Application.runWithContextHierarchy(Application.java:50)
at myapp.boot.Application.main(Application.java:33)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.builder.SpringApplicationBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more
build.gradle excerpt:
plugins {
id 'org.springframework.boot' version '1.5.22.RELEASE'
id 'java'
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
...
}
Turns out that Spring Boot 1 isn't able to work with implementation dependencies, but with (deprecated) compile dependencies.
Working build.gradle dependencies:
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
....
}

Transitive dependency missing in development mode

In a simple REST service built with Quarkus, a ClassNotFoundException is thrown if the service is run in development mode. With the uber-jar, it works correctly.
How can I get the service working in development mode too?
The missing class belongs to a transitive dependency of a QR bill generator library, which is declared build.gradle:
dependencies {
...
implementation 'net.codecrete.qrbill:qrbill-generator:2.2.2'
...
}
The error occurs in development mode (gradle quarkusDev) only. It is triggered if a REST request would need to use the qrbill:qrbill-generator library:
2020-05-03 12:11:49,463 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /xxx/yyy failed, error id: 89c5b7f8-c762-4f7f-959b-67f16b2bc120-1: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: io/nayuki/qrcodegen/QrCode$Ecc
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:515)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
[several lines omitted]
Caused by: java.lang.NoClassDefFoundError: io/nayuki/qrcodegen/QrCode$Ecc
at net.codecrete.qrbill.generator.QRCode.draw(QRCode.java:49)
at net.codecrete.qrbill.generator.BillLayout.drawPaymentPart(BillLayout.java:131)
at net.codecrete.qrbill.generator.BillLayout.draw(BillLayout.java:94)
[several lines omitted]
Caused by: java.lang.ClassNotFoundException: io.nayuki.qrcodegen.QrCode$Ecc
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:341)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:294)
... 44 more
When analyzing the dependencies, I can see that io.nayuki:qrcodegen:1.6.0 is part of the runtimeClasspath but not part of the compileClasspath. This looks ok.
Could it be that Quarkus dev mode uses the wrong classpath?

Where in SpringHow in Spring Boot do I solve a "java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext"?

I"m using Java 8 and Spring Boot. Trying to build a simple REST application that sits on a MongoDB. I have this in my Gradle build file
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-dependencies:2.1.5.RELEASE'
}
but when I go to start my app I get an error about not being able to find a class, "org/springframework/data/mapping/context/MappingContext":
localhost:todoapp-backend davea$ java -jar ./build/libs/spring-data-mongodb-example-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
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)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.context.MappingContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
What other dependency I'm I supposed to include to get the missing class found?
You should use Springboot Gradle plugin. It will solve all your dependecies issues .
plugins {
id 'java
id 'org.springframework.boot' version '2.1.5.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
}

Spring boot run error

The project spring boot 1..5.7 release. I am using Intellij IDEA 2017.2.4 and gradle for dependency management. When i build the project it builds successfully with no error. When I run the application with bootRun gradle task it shows the following error.
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:378)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:291)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.kifiya.lmanagement.LmanagementApplication.main(LmanagementApplication.java:13)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.event.EventPublishingRunListener]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)
... 6 more
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
at org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)
at org.springframework.boot.context.event.EventPublishingRunListener.(EventPublishingRunListener.java:56)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 7 more
It seems like a dependency problem within Spring, as it's mentioned above. The easiest way IMHO is to check your POM file.
Check out here for more info: https://docs.gradle.org/current/userguide/introduction_dependency_management.html
It looks like spring-aop doesn't match the rest of your libraries. Try running gradle dependencies and check that all Spring dependencies are in the same version. More on inspecting dependencies in Gradle User Manual.
Old question, but I had the same error after converting a Spring application to Spring Boot. Using the spring-boot-starter-aop instead of a direct dependency on a specific version of spring-aop resolved it for me, e.g. in build.gradle:
plugins {
id 'org.springframework.boot' version '1.5.17.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
compile 'org.springframework.boot:spring-boot-starter-aop'
}
instead of
dependencies {
compile 'org.springframework:spring-aop:4.2.4.RELEASE'
}

NoClassDefFoundError : ConfigurationPropertySources

Since yesterday we have a problem on our spring boot project after clean install without change nothing of configuration of the maven files, libs or something else.
We did try to update version of pom's of SpringFrameWork and Spring boot to 1.5.4.Release.
The error that is show is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/source/ConfigurationPropertySources
at org.springframework.cloud.client.HostInfoEnvironmentPostProcessor.getFirstNonLoopbackHostInfo(HostInfoEnvironmentPostProcessor.java:46)
at org.springframework.cloud.client.HostInfoEnvironmentPostProcessor.postProcessEnvironment(HostInfoEnvironmentPostProcessor.java:35)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:168)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:154)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:337)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at br.com.ibliss.auth.app.AuthServerApplication.main(AuthServerApplication.java:216)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.source.ConfigurationPropertySources
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more
According to ConfigurationPropertySources source, this class is around from version 2.0.0
Provides access to {#link ConfigurationPropertySource ConfigurationPropertySources}.
#author Phillip Webb
#since 2.0.0
You probably did not upgrade your spring boot version but actually downgrade.

Resources