Hibernate 3.6.10依赖关系解析 [英] Hibernate 3.6.10 Dependency resolution

查看:281
本文介绍了Hibernate 3.6.10依赖关系解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级了一个项目,使用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。

I recently upgraded a project to use hibernate 3.6.10.Final. The project uses ivy to retrieve and the dependencies. Now I'm getting an error that a method in slf4j cannot be found. I believe that this is due to conflicting slf4j dependencies between hibernate-core (requires 1.6.1) and hibernate-commons-annotations (requires 1.5.8). According to the hibernate-core ivy.xml hibernate-core is dependent on 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而不是String。

I checked the old slf4j javadoc and sure enough it looks like slf4j-1.6.1 has a format method that returns a FomattingTuple as opposed to a String.

以下是检索到的 hibernate-core-3.6.10.Final ivy.xml 文件来自maven2存储库:

Here's the hibernate-core-3.6.10.Final ivy.xml file that was retrieved from the maven2 repository:

<?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>

以下是 hibernate-commons-annotations-3.2.0.Final ivy.xml
$ b

Here's the hibernate-commons-annotations-3.2.0.Final ivy.xml file that was retrieved from the maven2 repository:

<?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>

我该如何解决这种依赖冲突?

How am I supposed to resolve this dependency conflict?

推荐答案

你的问题是在类路径中只能使用slf4j jar的一个副本,所以你需要决定保留哪一个。选择较旧的版本可能会修复一个编译错误,但会导致另一个错误: - )

Your problem is that only one copy of the slf4j jar can be used on the classpath, so you need to decide which one to keep. Choosing the older version might fix one compilation error, but cause another :-)

默认情况下,ivy会选择最新版本,假设它将向后兼容。您可以使用冲突指标覆盖此行为如下:

By default, ivy will choose the latest one on the assumption that it would be backwardly compatible. You can override this behaviour by using a conflict indicator as follows:

<dependencies>
    <dependency org="org.hibernate" name="hibernate-core" rev="3.6.10.Final" conf="compile->default"/>
    <dependency org="org.slf4j" name="slf4j-api" rev="1.5.8" conf="compile->default"/>

    <conflict org="org.slf4j" module="slf4j-api" rev="1.5.8"/>
</dependencies>

这篇关于Hibernate 3.6.10依赖关系解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆