Frage SLF4J-Fehler: Klassenlader hat verschiedene Klassenobjekte für den Typ


versuchen herauszufinden, warum ich den folgenden Fehler in Tomcat Logs bekomme:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature

In meinen grdle Dateien verwende ich slf4j Version 1.7.7, und in tomcat habe ich jul-zu-slf4j-1.7.7.jar und slf4j-api-1.7.7.jar, also bin ich ziemlich verwirrt.

Hier ist der Stack-Trace - Danke für jede Hilfe!

Total time: 2.982 secs
Using CATALINA_BASE:   /usr/local/Cellar/tomcat/8.0.18/libexec
Using CATALINA_HOME:   /usr/local/Cellar/tomcat/8.0.18/libexec
Using CATALINA_TMPDIR: /usr/local/Cellar/tomcat/8.0.18/libexec/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
Using CLASSPATH:       /usr/local/Cellar/tomcat/8.0.18/libexec/bin/jul-to-slf4j-1.7.7.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/slf4j-api-1.7.7.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-classic-1.1.2.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-core-1.1.2.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-config/:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/bootstrap.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/tomcat-juli.jar
19:03:55.979 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Server version:        Apache Tomcat/8.0.18
19:03:55.981 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Server built:          Jan 23 2015 11:56:07 UTC
19:03:55.981 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Server number:         8.0.18.0
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - OS Name:               Mac OS X
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - OS Version:            10.10
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Architecture:          x86_64
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Java Home:             /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - JVM Version:           1.8.0_25-b17
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - JVM Vendor:            Oracle Corporation
19:03:55.982 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - CATALINA_BASE:         /usr/local/Cellar/tomcat/8.0.18/libexec
19:03:55.983 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - CATALINA_HOME:         /usr/local/Cellar/tomcat/8.0.18/libexec
19:03:55.983 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Djava.util.logging.config.file=/usr/local/Cellar/tomcat/8.0.18/libexec/conf/logging.properties
19:03:55.983 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
19:03:55.983 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Djava.endorsed.dirs=/usr/local/Cellar/tomcat/8.0.18/libexec/endorsed
19:03:55.983 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Dcatalina.base=/usr/local/Cellar/tomcat/8.0.18/libexec
19:03:55.984 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Dcatalina.home=/usr/local/Cellar/tomcat/8.0.18/libexec
19:03:55.984 [main] INFO  org.apache.catalina.startup.VersionLoggerListener - Command line argument: -Djava.io.tmpdir=/usr/local/Cellar/tomcat/8.0.18/libexec/temp
19:03:55.984 [main] INFO  org.apache.catalina.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/jadekler/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
19:03:56.076 [main] INFO  org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"]
19:03:56.092 [main] INFO  org.apache.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
19:03:56.094 [main] INFO  org.apache.coyote.ajp.AjpNioProtocol - Initializing ProtocolHandler ["ajp-nio-8009"]
19:03:56.096 [main] INFO  org.apache.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
19:03:56.096 [main] INFO  org.apache.catalina.startup.Catalina - Initialization processed in 510 ms
19:03:56.115 [main] INFO  org.apache.catalina.core.StandardService - Starting service Catalina
19:03:56.115 [main] INFO  org.apache.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.0.18
19:03:56.132 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application archive /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/websiteskeleton.war
19:03:56.812 [localhost-startStop-1] ERROR org.apache.catalina.core.StandardContext - Error during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:160) ~[spring-web-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5143) ~[catalina.jar:8.0.18]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.18]
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) [catalina.jar:8.0.18]
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917) [catalina.jar:8.0.18]
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701) [catalina.jar:8.0.18]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_25]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_25]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:306) ~[slf4j-api-1.7.7.jar:1.7.7]
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276) ~[slf4j-api-1.7.7.jar:1.7.7]
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288) ~[slf4j-api-1.7.7.jar:1.7.7]
    at com.websiteskeleton.core.HelloInitializer.<init>(HelloInitializer.java:13) ~[HelloInitializer.class:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_25]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_25]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_25]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ~[na:1.8.0_25]
    at java.lang.Class.newInstance(Class.java:438) ~[na:1.8.0_25]
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:157) ~[spring-web-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    ... 12 common frames omitted
19:03:56.821 [localhost-startStop-1] ERROR org.apache.catalina.core.StandardContext - Context [/websiteskeleton] startup failed due to previous errors
19:03:56.825 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application archive /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/websiteskeleton.war has finished in 693 ms
19:03:56.826 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/docs
19:03:56.893 [localhost-startStop-1] INFO  org.apache.jasper.servlet.TldScanner - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
19:03:56.904 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/docs has finished in 78 ms
19:03:56.904 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/examples
19:03:57.133 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/examples has finished in 228 ms
19:03:57.133 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/host-manager
19:03:57.192 [localhost-startStop-1] INFO  org.apache.jasper.servlet.TldScanner - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
19:03:57.195 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/host-manager has finished in 62 ms
19:03:57.195 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/manager
19:03:57.252 [localhost-startStop-1] INFO  org.apache.jasper.servlet.TldScanner - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
19:03:57.254 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/manager has finished in 59 ms
19:03:57.254 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deploying web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/ROOT
19:03:57.307 [localhost-startStop-1] INFO  org.apache.jasper.servlet.TldScanner - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
19:03:57.308 [localhost-startStop-1] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory /usr/local/Cellar/tomcat/8.0.18/libexec/webapps/ROOT has finished in 54 ms
19:03:57.310 [main] INFO  org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"]
19:03:57.314 [main] INFO  org.apache.coyote.ajp.AjpNioProtocol - Starting ProtocolHandler ["ajp-nio-8009"]
19:03:57.315 [main] INFO  org.apache.catalina.startup.Catalina - Server startup in 1218 ms

5
2018-04-08 01:09


Ursprung


Antworten:


Das Tomcat-Protokoll zeigt, dass Sie eine weitere slf4j-1.7.7.jar im Klassenpfad haben:

Mit CLASSPATH: /usr/local/Cellar/tomcat/8.0.18/libexec/bin/jul-to-slf4j-1.7.7.jar:/usr/local/Cellar/tomcat/8.0.18/libexec/bin/slf4j-api-1.7.7.jar: /usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-classic-1.1.2.jar: /usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-core-1.1 .2.jar: /usr/local/Cellar/tomcat/8.0.18/libexec/bin/logback-config/: / usr / local / Keller / tomcat / 8.0.18 / libexec / bin / bootstrap.jar: / usr /local/Cellar/tomcat/8.0.18/libexec/bin/tomcat-juli.jar

Wenn Tomcat initialisiert wird, initialisiert es jul-to-slf4j und slf4j-api. Diese Jars werden vom Classloader geladen, der die Tomcat-Jars geladen hat (sun / misc / Launcher $ AppClassLoader).

Wenn Ihre Anwendung versucht, auf die slf4j-api-Klassen zuzugreifen, verwendet sie den WebApplication Classloader (org / apache / catalina / loader / WebappClassLoader), der standardmäßig nach der Klassendefinition im Klassenpfad der Anwendung vor dem Systemklassenpfad sucht. Beachten Sie, dass dies geändert werden kann: https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html

In Java besteht die Klassensignatur aus dem vollqualifizierten Klassennamen und dem Klassenlader, der die Klasse geladen hat. Wenn eine Klasse zweimal aus zwei verschiedenen Klassenladeprogrammen (derselben Hierarchie) geladen wird, gibt es zwei verschiedene Klassen für die JVM. Wenn Sie versuchen, eine Objektreferenz einer Klasse auf eine Variable der anderen Klasse zu verweisen, wird eine ClassCastException ausgelöst. In diesem Blogpost (Element 5) finden Sie weitere Informationen dazu: https://techblug.wordpress.com/2012/03/17/classloader-tips/

Soweit ich weiß, können Sie das beheben, indem Sie slf4j - *. Jar aus dem Tomcat-Klassenpfad entfernen. Wenn Sie mehr als eine Webanwendung mit derselben Version von slf4j verwenden, können Sie die jars aus der webapp entfernen Es werden die vom Tomcat-Classloader geladenen verwendet.


14
2018-04-08 02:12