我有一个Spring应用程序,Hibernate作为持久层。用于使用slf4j和log4j作为绑定来记录我。
我的pom.xml看起来像这样。
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
<hibernate.version>4.1.0.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!--DEPENDENCYS FOR HIBERNATE-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!--DEPENDENCY FOR BEANVALIDATION-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--DRIVER FOR MYSQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>2.2.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--REQUIRED FOR FILEUPLOAD-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3</version>
</dependency>
<!--LIB FOR JSON CONVERTING-->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<!-- Solr -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.0.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.4.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Logging-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
因此,当我使用Java 1.8在Ubuntu上的tomcat7上部署此应用程序时,一切正常(我的笔记本电脑)。但是当我尝试在生产系统上部署它时(Win 8,Java 7,Tomcat7和Tomcat8尝试过)我收到以下错误:
21-Oct-2014 17:57:50.016 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
21-Oct-2014 17:57:50.079 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
21-Oct-2014 17:57:50.079 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.AbstractMethodError: org.slf4j.impl.JDK14LoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
标准错误显示“由于之前的错误导致启动失败”......
任何想法可能是什么原因?
修改 来自'mvn dependency:tree'的依赖树看起来像这样:
[INFO] +- org.springframework:spring-core:jar:3.2.0.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-web:jar:3.2.0.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:3.2.0.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:3.2.0.RELEASE:compile
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-beans:jar:3.2.0.RELEASE:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided (scope not updated to compile)
[INFO] +- org.springframework:spring-webmvc:jar:3.2.0.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.2.0.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:3.2.0.RELEASE:test
[INFO] +- org.springframework:spring-orm:jar:3.2.0.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:3.2.0.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:3.2.0.RELEASE:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.1.0.Final:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] | +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:4.1.0.Final:compile
[INFO] | \- c3p0:c3p0:jar:0.9.1:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.1.0.Final:compile
[INFO] | \- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.18:compile
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.apache.tiles:tiles-extras:jar:2.2.2:compile
[INFO] | +- org.apache.tiles:tiles-core:jar:2.2.2:compile
[INFO] | | +- org.apache.tiles:tiles-api:jar:2.2.2:compile
[INFO] | | \- commons-digester:commons-digester:jar:2.0:compile
[INFO] | | \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | +- org.apache.tiles:tiles-servlet-wildcard:jar:2.2.2:compile
[INFO] | | \- org.apache.tiles:tiles-servlet:jar:2.2.2:compile
[INFO] | +- org.apache.tiles:tiles-jsp:jar:2.2.2:compile
[INFO] | | \- org.apache.tiles:tiles-template:jar:2.2.2:compile
[INFO] | +- org.apache.tiles:tiles-freemarker:jar:2.2.2:compile
[INFO] | | \- org.freemarker:freemarker:jar:2.3.15:compile
[INFO] | +- org.apache.tiles:tiles-velocity:jar:2.2.2:compile
[INFO] | | \- org.apache.velocity:velocity-tools:jar:2.0:compile
[INFO] | | +- oro:oro:jar:2.0.8:compile
[INFO] | | \- org.apache.velocity:velocity:jar:1.6.2:compile
[INFO] | +- org.apache.tiles:tiles-el:jar:2.2.2:compile
[INFO] | +- org.apache.tiles:tiles-mvel:jar:2.2.2:compile
[INFO] | | \- org.mvel:mvel2:jar:2.0.11:compile
[INFO] | +- org.apache.tiles:tiles-ognl:jar:2.2.2:compile
[INFO] | | \- ognl:ognl:jar:2.7.3:compile
[INFO] | | \- jboss:javassist:jar:3.7.ga:compile
[INFO] | \- org.apache.tiles:tiles-compat:jar:2.2.2:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] +- commons-io:commons-io:jar:1.3:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] +- org.springframework.data:spring-data-solr:jar:1.0.0.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.6.1.RELEASE:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.2.2:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.2.2:compile
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.2.2:compile
[INFO] | +- org.apache.httpcomponents:httpclient-cache:jar:4.2.2:compile
[INFO] | \- org.apache.solr:solr-solrj:jar:4.3.1:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO] | \- org.noggit:noggit:jar:0.5:compile
[INFO] +- org.apache.solr:solr-core:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-core:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-codecs:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-common:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-kuromoji:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-phonetic:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-highlighter:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-memory:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-misc:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-queryparser:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-spatial:jar:4.4.0:compile
[INFO] | | \- com.spatial4j:spatial4j:jar:0.3:compile
[INFO] | +- org.apache.lucene:lucene-suggest:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-grouping:jar:4.4.0:compile
[INFO] | +- org.apache.lucene:lucene-queries:jar:4.4.0:compile
[INFO] | +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2:compile
[INFO] | +- commons-codec:commons-codec:jar:1.7:compile
[INFO] | +- commons-cli:commons-cli:jar:1.2:compile
[INFO] | +- joda-time:joda-time:jar:2.2:compile
[INFO] | +- org.apache.hadoop:hadoop-annotations:jar:2.0.5-alpha:compile
[INFO] | | \- jdk.tools:jdk.tools:jar:1.6:system
[INFO] | +- org.apache.hadoop:hadoop-auth:jar:2.0.5-alpha:compile
[INFO] | +- org.apache.hadoop:hadoop-common:jar:2.0.5-alpha:compile
[INFO] | | +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] | | +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] | | +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] | | \- com.google.protobuf:protobuf-java:jar:2.4.0a:compile
[INFO] | +- org.apache.hadoop:hadoop-hdfs:jar:2.0.5-alpha:compile
[INFO] | +- org.restlet.jee:org.restlet:jar:2.1.1:compile
[INFO] | +- org.restlet.jee:org.restlet.ext.servlet:jar:2.1.1:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- com.google.guava:guava:jar:14.0.1:compile
[INFO] | \- org.codehaus.woodstox:wstx-asl:jar:3.2.7:runtime
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] \- log4j:log4j:jar:1.2.17:compile
编辑2
所以......现在我试图从我的项目pom.xml中排除commons-logging
个东西。但它也不是很有效。错误信息保持完全相同......但我认识到一些非常有趣的事情......
当我用存档管理器打开输出war(我使用mvn clean install
生成它)并导航到WEB-INF / lib文件夹时,我可以看到我的pom.xml中的所有jar文件在过去。因此,有3个不同版本的slf4j的罐子,多个log4j版本和许多其他库,可能会发生冲突。
奇怪的是,所有这些jar文件都没有出现在mvn dependency:tree
。
任何想法,我怎么能摆脱这些文件?