首页 > 解决方案 > ClassNotFoundException: org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator on spring boot 2.3.4 and log4j 2.13.3

问题描述

I'm trying to run log4j 2.13.3(latest release) with spring boot 2.3.4.RELEASE (latest release), but I'm getting the following error when starting my app:

mix-data-collector_1     | ------------------------------------------------------------------------
mix-data-collector_1     | OpenJDK 64-Bit Server VM warning: Ignoring option PermSize; support was removed in 8.0
mix-data-collector_1     | DB update completed
mix-data-collector_1     | DB migration finished
mix-data-collector_1     | Start Mix Data Collector---------------------------------------------
mix-data-collector_1     | Listening for transport dt_socket at address: 5555
mix-data-collector_1     | Exception in thread "main" java.lang.reflect.InvocationTargetException
mix-data-collector_1     |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
mix-data-collector_1     |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
mix-data-collector_1     |      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
mix-data-collector_1     |      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
mix-data-collector_1     |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
mix-data-collector_1     loader.Launcher.launch(Launcher.java:87)
mix-data-collector_1     |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
mix-data-collector_1     |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
mix-data-collector_1     | Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/StackLocator$FqcnCallerLocator
mix-data-collector_1     |      at org.apache.logging.log4j.util.StackLocator.<clinit>(StackLocator.java:37)
mix-data-collector_1     |      at org.apache.logging.log4j.util.StackLocatorUtil.<clinit>(StackLocatorUtil.java:33)
mix-data-collector_1     |      at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:133)
mix-data-collector_1     |      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:228)
mix-data-collector_1     |      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
mix-data-collector_1     |      at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
mix-data-collector_1     |      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.getLoggerContext(Log4J2LoggingSystem.java:305)
mix-data-collector_1     |      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.beforeInitialize(Log4J2LoggingSystem.java:145)
mix-data-collector_1     |      at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:232)
mix-data-collector_1     |      at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
mix-data-collector_1     |      at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:74)
mix-data-collector_1     |      at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
mix-data-collector_1     |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
mix-data-collector_1     |      at ch.sbb.esta.openshift.gracefullshutdown.GracefulshutdownSpringApplication.run(GracefulshutdownSpringApplication.java:21)
mix-data-collector_1     |      at com.nuance.core.mix.data.collector.Application.main(Application.java:38)
mix-data-collector_1     |      ... 8 more
mix-data-collector_1     | Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator
mix-data-collector_1     |      at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
mix-data-collector_1     |      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
mix-data-collector_1     |      at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
mix-data-collector_1     |      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
mix-data-collector_1     |      ... 27 more
mix-data-collector_mix-data-collector_1 exited with code 1loader.Launcher.launch(Launcher.java:87)
mix-data-collector_1     |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
mix-data-collector_1     |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
mix-data-collector_1     | Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/StackLocator$FqcnCallerLocator
mix-data-collector_1     |      at org.apache.logging.log4j.util.StackLocator.<clinit>(StackLocator.java:37)
mix-data-collector_1     |      at org.apache.logging.log4j.util.StackLocatorUtil.<clinit>(StackLocatorUtil.java:33)
mix-data-collector_1     |      at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:133)
mix-data-collector_1     |      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:228)
mix-data-collector_1     |      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
mix-data-collector_1     |      at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
mix-data-collector_1     |      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.getLoggerContext(Log4J2LoggingSystem.java:305)
mix-data-collector_1     |      at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.beforeInitialize(Log4J2LoggingSystem.java:145)
mix-data-collector_1     |      at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:232)
mix-data-collector_1     |      at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
mix-data-collector_1     |      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
mix-data-collector_1     |      at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:74)
mix-data-collector_1     |      at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
mix-data-collector_1     |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
mix-data-collector_1     |      at ch.sbb.esta.openshift.gracefullshutdown.GracefulshutdownSpringApplication.run(GracefulshutdownSpringApplication.java:21)
mix-data-collector_1     |      at com.nuance.core.mix.data.collector.Application.main(Application.java:38)
mix-data-collector_1     |      ... 8 more
mix-data-collector_1     | Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator
mix-data-collector_1     |      at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
mix-data-collector_1     |      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
mix-data-collector_1     |      at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
mix-data-collector_1     |      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
mix-data-collector_1     |      ... 27 more
mix-data-collector_mix-data-collector_1 exited with code 1

My maven dependencies look like this:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j.version}</version>
</dependency>

With log4j 2.11.2 the app starts ok (so there is something that got changed in the latest log4j version), but i need to move to version 2.13.3 in order to mitigate some security issues. Any idea how i can solve this problems?

Thanks enter image description here

latest dependencies: enter image description here

标签: springspring-bootlog4j

解决方案


好的,我发现了我的问题。似乎还有一个导致问题的spring maven插件依赖项。谢谢您的帮助


推荐阅读