stefanhgm
stefanhgm

Reputation: 55

Maven project: SolrJ with slf4j and logback logging causes SolrException: Error loading class 'org.slf4j.Logger;org.slf4j.Logger'

I have got the following setup: A Spring application that makes use of SolrJ with slf4j logging over logback. When I start the application on my tomcat server the below error appears. So, somehow SolrJ does not find the slf4j logging component, but I verified that the according .jar file is actually in the correct lib folder of my WAR.

2017-05-12 09:37:54,094 WARN  [org.apache.solr.common.SolrException: Error loading class 'org.slf4j.Logger;org.slf4j.Logger'
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:556)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:625)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:590)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:583)
    at org.apache.solr.logging.LogWatcher.createWatcher(LogWatcher.java:181)
    at org.apache.solr.logging.LogWatcher.newRegisteredLogWatcher(LogWatcher.java:134)
    at org.apache.solr.core.CoreContainer.load(CoreContainer.java:473)
    at de.imi.MDMJava.config.AppConfig.solrClient(AppConfig.java:259)
    at de.imi.MDMJava.config.AppConfig$$EnhancerBySpringCGLIB$$ece8fb2.CGLIB$solrClient$9(<generated>)
    at de.imi.MDMJava.config.AppConfig$$EnhancerBySpringCGLIB$$ece8fb2$$FastClassBySpringCGLIB$$2023340f.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    at de.imi.MDMJava.config.AppConfig$$EnhancerBySpringCGLIB$$ece8fb2.solrClient(<generated>)
    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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    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:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    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:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    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.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4810)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1692)
    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:465)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:415)
    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org/slf4j/Logger;org/slf4j/Logger
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:540)
    ... 103 common frames omitted
] in LogWatcher.java:createWatcher:184: Unable to load LogWatcher org.slf4j.Logger;org.slf4j.Logger: {}
2017-05-12 09:37:55,991 WARN  [] in WebSecurity.java:performBuild:300: 

My pom.xml for the loggin part looks like this:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.2.3</version>
    </dependency>

And the Maven dependency tree looks as follow:

$ mvn dependency:tree -Dverbose | grep slf4j
[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.21:compile - omitted for conflict with 1.7.7)
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.7.7:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.25)

Unfortunately the full dependency tree is too long for this post, but if you need any further information just let me know. Thanks for any suggestions.

Edit 1:

There is a "slf4j-api-1.7.25.jar" file in my "/WEB-INF/lib/" directory of my WAR file that contains all libraries.

The full Maven dependency tree where I stripped the parts that don't contain "slf4j":

[more dependencies, but no occurence of slf4j...]
[INFO] +- org.springframework.security:spring-security-ldap:jar:4.2.2.RELEASE:compile
[INFO] |  +- org.springframework.ldap:spring-ldap-core:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.21:compile - omitted for conflict with 1.7.7)
[INFO] |  +- (org.springframework.security:spring-security-core:jar:4.2.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  \- (org.springframework:spring-tx:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] +- org.springframework.security:spring-security-openid:jar:4.2.2.RELEASE:compile
[INFO] |  +- com.google.inject:guice:jar:2.0:compile
[INFO] |  |  \- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  +- org.openid4java:openid4java-nodeps:jar:0.9.6:compile
[INFO] |  |  \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] |  +- (org.springframework.security:spring-security-core:jar:4.2.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework.security:spring-security-web:jar:4.2.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-aop:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- (org.springframework:spring-web:jar:4.3.5.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.20:runtime
[INFO] |  |  \- xerces:xercesImpl:jar:2.10.0:runtime
[INFO] |  |     \- (xml-apis:xml-apis:jar:1.4.01:runtime - omitted for conflict with 1.0.b2)
[INFO] |  \- (org.apache.httpcomponents:httpclient:jar:4.2.3:compile - scope updated from runtime; omitted for duplicate)
[INFO] +- org.apache.solr:solr-core:jar:6.5.1:compile
[more dependencies, but no occurence of slf4j...]
[INFO] |  +- org.restlet.jee:org.restlet:jar:2.3.0:compile
[INFO] |  +- org.restlet.jee:org.restlet.ext.servlet:jar:2.3.0:compile
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] +- org.apache.solr:solr-solrj:jar:6.5.1:compile
[INFO] |  +- (commons-io:commons-io:jar:2.5:compile - omitted for duplicate)
[INFO] |  +- (org.apache.httpcomponents:httpclient:jar:4.4.1:compile - omitted for conflict with 4.2.3)
[INFO] |  +- (org.apache.httpcomponents:httpcore:jar:4.4.1:compile - omitted for duplicate)
[INFO] |  +- (org.apache.httpcomponents:httpmime:jar:4.4.1:compile - omitted for duplicate)
[INFO] |  +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for duplicate)
[INFO] |  +- (org.codehaus.woodstox:stax2-api:jar:3.1.4:compile - omitted for duplicate)
[INFO] |  +- (org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile - omitted for duplicate)
[INFO] |  +- (org.noggit:noggit:jar:0.6:compile - omitted for duplicate)
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.7.7:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
[INFO] +- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  +- (ch.qos.logback:logback-core:jar:1.2.3:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.8.8:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.8:compile
[INFO] |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile - omitted for conflict with 2.5.4)
[INFO] |  \- (com.fasterxml.jackson.core:jackson-core:jar:2.8.8:compile - omitted for duplicate)
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.8:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  +- (org.apache.httpcomponents:httpcore:jar:4.4.4:compile - omitted for conflict with 4.4.1)
[INFO] |  \- (commons-codec:commons-codec:jar:1.9:compile - omitted for conflict with 1.10)
[INFO] +- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] +- org.jdom:jdom:jar:1.1:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- org.apache.tiles:tiles-extras:jar:3.0.5:compile
[INFO] |  +- org.apache.tiles:tiles-core:jar:3.0.5:compile
[INFO] |  |  +- org.apache.tiles:tiles-api:jar:3.0.5:compile
[INFO] |  |  |  \- (org.apache.tiles:tiles-request-api:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  |  \- commons-digester:commons-digester:jar:2.0:compile
[INFO] |  |     \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  +- org.apache.tiles:tiles-request-servlet-wildcard:jar:1.0.6:compile
[INFO] |  |  +- org.apache.tiles:tiles-request-servlet:jar:1.0.6:compile
[INFO] |  |  |  \- (org.apache.tiles:tiles-request-api:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-web:jar:3.2.0.RELEASE:compile - omitted for conflict with 4.3.7.RELEASE)
[INFO] |  +- org.apache.tiles:tiles-request-mustache:jar:1.0.6:compile
[INFO] |  |  +- org.apache.tiles:tiles-request-api:jar:1.0.6:compile
[INFO] |  |  \- com.github.spullara.mustache.java:compiler:jar:0.8.4:compile
[INFO] |  |     \- (com.google.guava:guava:jar:12.0:compile - omitted for conflict with 14.0.1)
[INFO] |  +- org.apache.tiles:tiles-jsp:jar:3.0.5:compile
[INFO] |  |  +- org.apache.tiles:tiles-servlet:jar:3.0.5:compile
[INFO] |  |  |  +- (org.apache.tiles:tiles-core:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  |  \- (org.apache.tiles:tiles-request-servlet:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  |  +- org.apache.tiles:tiles-template:jar:3.0.5:compile
[INFO] |  |  |  +- (org.apache.tiles:tiles-api:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  |  \- org.apache.tiles:tiles-autotag-core-runtime:jar:1.1.0:compile
[INFO] |  |  \- org.apache.tiles:tiles-request-jsp:jar:1.0.6:compile
[INFO] |  |     +- (org.apache.tiles:tiles-request-api:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  |     \- (org.apache.tiles:tiles-request-servlet:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  +- org.apache.tiles:tiles-freemarker:jar:3.0.5:compile
[INFO] |  |  +- (org.apache.tiles:tiles-servlet:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.tiles:tiles-template:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  \- org.apache.tiles:tiles-request-freemarker:jar:1.0.6:compile
[INFO] |  |     +- (org.apache.tiles:tiles-request-api:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  |     +- org.freemarker:freemarker:jar:2.3.15:compile
[INFO] |  |     \- (org.apache.tiles:tiles-request-servlet:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  +- org.apache.tiles:tiles-velocity:jar:3.0.5:compile
[INFO] |  |  +- (org.apache.tiles:tiles-servlet:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.tiles:tiles-template:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  +- org.apache.velocity:velocity-tools:jar:2.0:compile
[INFO] |  |  |  +- (commons-collections:commons-collections:jar:3.2:compile - omitted for conflict with 3.2.2)
[INFO] |  |  |  +- oro:oro:jar:2.0.8:compile
[INFO] |  |  |  \- org.apache.velocity:velocity:jar:1.6.2:compile
[INFO] |  |  |     +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for conflict with 3.2.2)
[INFO] |  |  |     +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
[INFO] |  |  |     \- (oro:oro:jar:2.0.8:compile - omitted for duplicate)
[INFO] |  |  +- (commons-digester:commons-digester:jar:2.0:compile - omitted for duplicate)
[INFO] |  |  \- org.apache.tiles:tiles-request-velocity:jar:1.0.6:compile
[INFO] |  |     +- (org.apache.velocity:velocity-tools:jar:2.0:compile - omitted for duplicate)
[INFO] |  |     \- (org.apache.tiles:tiles-request-servlet:jar:1.0.6:compile - omitted for duplicate)
[INFO] |  +- org.apache.tiles:tiles-el:jar:3.0.5:compile
[INFO] |  |  \- (org.apache.tiles:tiles-core:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  +- org.apache.tiles:tiles-mvel:jar:3.0.5:compile
[INFO] |  |  +- (org.apache.tiles:tiles-core:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  \- org.mvel:mvel2:jar:2.0.11:compile
[INFO] |  +- org.apache.tiles:tiles-ognl:jar:3.0.5:compile
[INFO] |  |  +- (org.apache.tiles:tiles-core:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  \- ognl:ognl:jar:2.7.3:compile
[INFO] |  |     \- jboss:javassist:jar:3.7.ga:compile
[INFO] |  +- org.apache.tiles:tiles-compat:jar:3.0.5:compile
[INFO] |  |  +- (org.apache.tiles:tiles-core:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  |  \- (org.apache.tiles:tiles-jsp:jar:3.0.5:compile - omitted for duplicate)
[INFO] |  \- (com.google.guava:guava:jar:12.0.1:compile - omitted for conflict with 14.0.1)
[INFO] +- javax:javaee-web-api:jar:7.0:provided
[INFO] +- org.projectlombok:lombok:jar:1.16.10:provided
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.2:provided
[INFO] +- javax.mail:mail:jar:1.4.7:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- cglib:cglib:jar:2.2.2:compile
[INFO] |  \- asm:asm:jar:3.3.1:compile
[INFO] +- org.webjars:jquery:jar:3.2.0:compile
[INFO] +- org.webjars:bootstrap:jar:3.3.7:compile
[INFO] |  \- (org.webjars:jquery:jar:1.11.1:compile - omitted for conflict with 3.2.0)
[INFO] +- org.webjars.bower:devbridge-autocomplete:jar:1.3.0:compile
[INFO] |  \- org.webjars.bower:jquery:jar:3.2.1:compile
[INFO] +- org.webjars:webjars-locator:jar:0.32:compile
[INFO] |  +- org.webjars:webjars-locator-core:jar:0.30:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] |  |  \- org.apache.commons:commons-compress:jar:1.9:compile
[INFO] |  \- (com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile - omitted for conflict with 2.8.8)
[INFO] \- com.github.dpaukov:combinatoricslib3:jar:3.1.1:compile

Edit 2:

Here is the content of the slf4j-api-1.7.25.jar in the WAR package. The "org/slf4j/Logger.class" seems to exist. When I deploy the webapp, slf4j-api-1.7.25.jar has 644 rights and my user is the owner of the file. Can that cause the problem?

slf4j-api-1.7.25
├── META-INF
│   ├── MANIFEST.MF
│   └── maven
│       └── org.slf4j
│           └── slf4j-api
│               ├── pom.properties
│               └── pom.xml
└── org
    └── slf4j
        ├── event
        │   ├── EventConstants.class
        │   ├── EventRecodingLogger.class
        │   ├── Level.class
        │   ├── LoggingEvent.class
        │   └── SubstituteLoggingEvent.class
        ├── helpers
        │   ├── BasicMarker.class
        │   ├── BasicMarkerFactory.class
        │   ├── BasicMDCAdapter$1.class
        │   ├── BasicMDCAdapter.class
        │   ├── FormattingTuple.class
        │   ├── MarkerIgnoringBase.class
        │   ├── MessageFormatter.class
        │   ├── NamedLoggerBase.class
        │   ├── NOPLogger.class
        │   ├── NOPLoggerFactory.class
        │   ├── NOPMDCAdapter.class
        │   ├── SubstituteLogger.class
        │   ├── SubstituteLoggerFactory.class
        │   ├── Util$1.class
        │   ├── Util.class
        │   └── Util$ClassContextSecurityManager.class
        ├── ILoggerFactory.class
        ├── IMarkerFactory.class
        ├── Logger.class
        ├── LoggerFactory.class
        ├── Marker.class
        ├── MarkerFactory.class
        ├── MDC$1.class
        ├── MDC.class
        ├── MDC$MDCCloseable.class
        └── spi
            ├── LocationAwareLogger.class
            ├── LoggerFactoryBinder.class
            ├── MarkerFactoryBinder.class
            └── MDCAdapter.class

Edit 3: @AlexC you were right. I grepped for ".Logger;" and found this line in my solr.xml:

<str name="class">${loggingClass:org.slf4j.Logger;org.slf4j.Logger}</str>

I changed it to:

<logging>
    <str name="class">${loggingClass:org.slf4j.Logger}</str>
    <str name="enabled">${loggingEnabled:true}</str>
    <watcher>
      <int name="size">${loggingSize:50}</int>
      <str name="threshold">${loggingThreshold:WARN}</str>
    </watcher>
  </logging>

Still the same error but now with "org.slf4j.Logger" instead (with jcl-over-slf4j, logback-core and without):

2017-05-12 14:33:16,411 WARN  [java.lang.ClassCastException: interface org.slf4j.Logger
    at java.lang.Class.asSubclass(Class.java:3404)
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:540)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:625)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:590)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:583)
    at org.apache.solr.logging.LogWatcher.createWatcher(LogWatcher.java:181)
    at org.apache.solr.logging.LogWatcher.newRegisteredLogWatcher(LogWatcher.java:134)
    at org.apache.solr.core.CoreContainer.load(CoreContainer.java:473)
    [...]
    at java.lang.Thread.run(Thread.java:745)
] in LogWatcher.java:createWatcher:184: Unable to load LogWatcher org.slf4j.Logger: {}

Edit 4:

Maybe to clarify this for everyone from my below comment: "Solr is integrated into my application via SolrJ. I do not run a separate Solr instance. I know this should only be done for debugging purpose but my usage of Solr does not justify a standalone Solr server."

I tried to removed all dependencies of slf4j via exclusions in my pom.xml. The only remaining dependencies are now:

[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  +- (ch.qos.logback:logback-core:jar:1.2.3:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
[INFO] +- ch.qos.logback:logback-core:jar:1.2.3:compile

Upvotes: 1

Views: 1037

Answers (1)

stefanhgm
stefanhgm

Reputation: 55

I have found a workaround for my setup. First I added all kind of connectors to slf4j logging into my pom.xml, due to the following sentence in the Solr wiki.

If you use an entirely different logging mechanism like logback, then you must have intercepts for all three - JUL, JCL, and log4j.

Furthermore I found the Solr Code that causes my logging problems in the class LogWatcher.java line 184 (also see exception message in my question). Here is an excerpt of the code from Github.

  private static LogWatcher createWatcher(LogWatcherConfig config, SolrResourceLoader loader) {

    String fname = config.getLoggingClass();
    String slf4jImpl;

    try {
      slf4jImpl = StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr();
      log.debug("SLF4J impl is " + slf4jImpl);
      if (fname == null) {
        if ("org.slf4j.impl.Log4jLoggerFactory".equals(slf4jImpl)) {
          fname = "Log4j";
        } else if (slf4jImpl.indexOf("JDK") > 0) {
          fname = "JUL";
        }
      }
    }
    catch (Throwable e) {
      log.warn("Unable to read SLF4J version.  LogWatcher will be disabled: " + e);
      if (e instanceof OutOfMemoryError) {
        throw (OutOfMemoryError) e;
      }
      return null;
    }

    if (fname == null) {
      log.debug("No LogWatcher configured");
      return null;
    }

    if ("JUL".equalsIgnoreCase(fname))
      return new JulWatcher(slf4jImpl);
    if ("Log4j".equals(fname))
      return new Log4jWatcher(slf4jImpl);

    try {
      return loader != null ? loader.newInstance(fname, LogWatcher.class) : null;
    }
    catch (Throwable e) {
      log.warn("Unable to load LogWatcher {}: {}", fname, e);
      if (e instanceof OutOfMemoryError) {
        throw (OutOfMemoryError) e;
      }
    }

    return null;
  }
}

The problematic part is the last try/catch block, so it seems like fname == "org.slf4j.Logger" is not valid. However, as we can see at the top of the code if fname == null the string "Log4j" is used as fall back. So, I simply decided to go with "Log4j" in my solr logging configuration (as shown below) and let the log4j-over-slf4j connector handle the connection to slf4j.

<solr>

    ...

    <logging>
        <str name="class">Log4j</str>
        <bool name="enabled">true</bool>
        <!-- default watcher param -->
        <watcher>
            <int name="size">50</int>
            <str name="threshold">FINEST</str>
        </watcher>
    </logging>

    ...

</solr>

I guess this is not the perfect solution, but for me it seems like a good enough work around.

Upvotes: 1

Related Questions