我最近升级了一个项目以使用 hibernate 3.6.10.Final。该项目使用常春藤检索和依赖项。现在我收到一个错误,找不到 slf4j 中的方法。我相信这是由于 hibernate-core(需要 1.6.1)和 hibernate-commons-annotations(需要 1.5.8)之间的冲突 slf4j 依赖关系。根据hibernate-core ivy.xml,hibernate-core依赖于hibernate-commons-annotations。
这是我得到的错误:
Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;:
java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
at org.slf4j.impl.JDK14LoggerAdapter.info(JDK14LoggerAdapter.java:303)
at org.hibernate.annotations.common.Version.<clinit>(Version.java:37)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit>(JavaReflectionManager.java:73)
at org.hibernate.cfg.Configuration.createReflectionManager(Configuration.java:2988)
at org.hibernate.cfg.Configuration.createReflectionManager(Configuration.java:2984)
at org.hibernate.cfg.Configuration.reset(Configuration.java:307)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:298)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:302)
at mb.common.hibernate.cfg.DefaultEnhancedConfiguration.<init>(DefaultEnhancedConfiguration.java:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
我检查了旧的 slf4j javadoc,果然看起来 slf4j-1.6.1 有一个格式方法,它返回一个 FomattingTuple 而不是一个字符串。
这是从 maven2 存储库中检索到的hibernate-core-3.6.10.Final ivy.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="org.hibernate"
module="hibernate-core"
revision="3.6.10.Final"
status="release"
publication="20120208201903"
>
<description homepage="">
The core functionality of Hibernate
</description>
<m:dependency.management__javassist__javassist__version>3.12.0.GA</m:dependency.management__javassist__javassist__version>
<m:properties__bytemanVersion>1.5.1</m:properties__bytemanVersion>
<m:dependency.management__commons-collections__commons-collections__version>3.1</m:dependency.management__commons-collections__commons-collections__version>
<m:dependency.management__javax.validation__validation-api__version>1.0.0.GA</m:dependency.management__javax.validation__validation-api__version>
<m:dependency.management__dom4j__dom4j__version>1.6.1</m:dependency.management__dom4j__dom4j__version>
<m:dependency.management__org.hibernate__hibernate-validator__version>4.1.0.Final</m:dependency.management__org.hibernate__hibernate-validator__version>
<m:dependency.management__cglib__cglib__version>2.2</m:dependency.management__cglib__cglib__version>
<m:dependency.management__org.hibernate.javax.persistence__hibernate-jpa-2.0-api__version>1.0.1.Final</m:dependency.management__org.hibernate.javax.persistence__hibernate-jpa-2.0-api__version>
<m:dependency.management__com.h2database__h2__version>1.2.145</m:dependency.management__com.h2database__h2__version>
<m:properties__project.build.sourceEncoding>UTF-8</m:properties__project.build.sourceEncoding>
<m:properties__slf4jVersion>1.6.1</m:properties__slf4jVersion>
<m:dependency.management__org.slf4j__slf4j-api__version>1.6.1</m:dependency.management__org.slf4j__slf4j-api__version>
<m:dependency.management__antlr__antlr__version>2.7.6</m:dependency.management__antlr__antlr__version>
<m:dependency.management__org.hibernate__hibernate-commons-annotations__version>3.2.0.Final</m:dependency.management__org.hibernate__hibernate-commons-annotations__version>
<m:properties__antlrPluginVersion>2.1</m:properties__antlrPluginVersion>
<m:dependency.management__org.jboss.byteman__byteman__version>1.5.1</m:dependency.management__org.jboss.byteman__byteman__version>
<m:maven.plugins>org.jboss.maven.plugins__maven-jdocbook-style-plugin__null|org.codehaus.groovy.maven__gmaven-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__null|org.apache.maven.plugins__maven-compiler-plugin__null|org.apache.maven.plugins__maven-jar-plugin__null|org.apache.maven.plugins__maven-surefire-plugin__null|org.apache.maven.plugins__maven-source-plugin__null|org.jboss.maven.plugins__maven-jdocbook-style-plugin__null|org.codehaus.groovy.maven__gmaven-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__null|org.apache.maven.plugins__maven-compiler-plugin__null|org.apache.maven.plugins__maven-jar-plugin__null|org.apache.maven.plugins__maven-surefire-plugin__null|org.apache.maven.plugins__maven-source-plugin__null|org.codehaus.mojo__antlr-maven-plugin__2.1|org.jboss.maven.plugins__maven-injection-plugin__null|null__maven-jar-plugin__null</m:maven.plugins>
</info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
<conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
<conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
<conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
<conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
<conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/>
<conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
<conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
<conf name="optional" visibility="public" description="contains all optional dependencies"/>
</configurations>
<publications>
<artifact name="hibernate-core" type="jar" ext="jar" conf="master"/>
<artifact name="hibernate-core" type="source" ext="jar" conf="sources" m:classifier="sources"/>
</publications>
<dependencies>
<dependency org="antlr" name="antlr" rev="2.7.6" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="commons-collections" name="commons-collections" rev="3.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)">
<exclude org="xml-apis" module="xml-apis" name="*" type="*" ext="*" conf="" matcher="exact"/>
</dependency>
<dependency org="org.hibernate" name="hibernate-commons-annotations" rev="3.2.0.Final" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.0-api" rev="1.0.1.Final" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="javax.validation" name="validation-api" rev="1.0.0.GA" force="true" conf="provided->compile(*),provided(*),runtime(*),master(*)"/>
<dependency org="org.hibernate" name="hibernate-validator" rev="4.1.0.Final" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.2" force="true" conf="test->runtime(*),master(*)">
<exclude org="javax.xml.stream" module="stax-api" name="*" type="*" ext="*" conf="" matcher="exact"/>
<exclude org="javax.activation" module="activation" name="*" type="*" ext="*" conf="" matcher="exact"/>
</dependency>
<dependency org="com.sun.xml.bind" name="jaxb-impl" rev="2.1.12" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="javassist" name="javassist" rev="3.12.0.GA" force="true" conf="optional->compile(*),master(*)"/>
<dependency org="cglib" name="cglib" rev="2.2" force="true" conf="optional->compile(*),master(*)"/>
<dependency org="javax.transaction" name="jta" rev="1.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="org.jboss.javaee" name="jboss-jacc-api_JDK4" rev="1.1.0" force="true" conf="provided->compile(*),provided(*),runtime(*),master(*)">
<exclude org="org.jboss.javaee" module="jboss-servlet-api_3.0" name="*" type="*" ext="*" conf="" matcher="exact"/>
<exclude org="org.jboss.logging" module="jboss-logging-spi" name="*" type="*" ext="*" conf="" matcher="exact"/>
<exclude org="org.jboss" module="jboss-common-core" name="*" type="*" ext="*" conf="" matcher="exact"/>
</dependency>
<dependency org="ant" name="ant" rev="1.6.5" force="true" conf="provided->compile(*),provided(*),runtime(*),master(*)"/>
<dependency org="com.h2database" name="h2" rev="1.2.145" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="junit" name="junit" rev="3.8.1" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.1" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.1" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="commons-logging" name="commons-logging" rev="99.0-does-not-exist" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="commons-logging" name="commons-logging-api" rev="99.0-does-not-exist" force="true" conf="test->runtime(*),master(*)"/>
<override org="commons-collections" module="commons-collections" matcher="exact" rev="3.1"/>
<override org="org.hibernate" module="hibernate-validator" matcher="exact" rev="4.1.0.Final"/>
<override org="javassist" module="javassist" matcher="exact" rev="3.12.0.GA"/>
<override org="org.jboss.byteman" module="byteman" matcher="exact" rev="1.5.1"/>
<override org="cglib" module="cglib" matcher="exact" rev="2.2"/>
<override org="org.hibernate.javax.persistence" module="hibernate-jpa-2.0-api" matcher="exact" rev="1.0.1.Final"/>
<override org="com.h2database" module="h2" matcher="exact" rev="1.2.145"/>
<override org="org.hibernate" module="hibernate-commons-annotations" matcher="exact" rev="3.2.0.Final"/>
<override org="org.slf4j" module="slf4j-api" matcher="exact" rev="1.6.1"/>
<override org="antlr" module="antlr" matcher="exact" rev="2.7.6"/>
<override org="javax.validation" module="validation-api" matcher="exact" rev="1.0.0.GA"/>
<override org="dom4j" module="dom4j" matcher="exact" rev="1.6.1"/>
</dependencies>
</ivy-module>
这是从 maven2 存储库中检索到的hibernate-commons-annotations-3.2.0.Final ivy.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="org.hibernate"
module="hibernate-commons-annotations"
revision="3.2.0.Final"
status="release"
publication="20100309114153"
>
<license name="GNU LESSER GENERAL PUBLIC LICENSE" url="http://www.gnu.org/licenses/lgpl.txt" />
<description homepage="http://hibernate.org">
Common reflection code used in support of annotation processing
</description>
<m:dependency.management__org.slf4j__slf4j-api__version>1.5.8</m:dependency.management__org.slf4j__slf4j-api__version>
<m:properties__slf4jVersion>1.5.8</m:properties__slf4jVersion>
<m:maven.plugins>org.apache.maven.plugins__maven-compiler-plugin__null</m:maven.plugins>
</info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
<conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
<conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
<conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
<conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
<conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/>
<conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
<conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
<conf name="optional" visibility="public" description="contains all optional dependencies"/>
</configurations>
<publications>
<artifact name="hibernate-commons-annotations" type="jar" ext="jar" conf="master"/>
<artifact name="hibernate-commons-annotations" type="source" ext="jar" conf="sources" m:classifier="sources"/>
<artifact name="hibernate-commons-annotations" type="javadoc" ext="jar" conf="javadoc" m:classifier="javadoc"/>
</publications>
<dependencies>
<dependency org="org.slf4j" name="slf4j-api" rev="1.5.8" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
<dependency org="junit" name="junit" rev="3.8.1" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.5.8" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.5.8" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="commons-logging" name="commons-logging" rev="99.0-does-not-exist" force="true" conf="test->runtime(*),master(*)"/>
<dependency org="commons-logging" name="commons-logging-api" rev="99.0-does-not-exist" force="true" conf="test->runtime(*),master(*)"/>
<override org="org.slf4j" module="slf4j-api" matcher="exact" rev="1.5.8"/>
</dependencies>
</ivy-module>
我应该如何解决这种依赖冲突?