当前位置: 首页 > 面试题库 >

Hibernate 3.6.10依赖关系解析

何兴学
2023-03-14
问题内容

我最近升级了一个项目以使用hibernate3.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而不是String。

这是从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>

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


问题答案:

您的问题是在类路径上只能使用slf4j jar的一个副本,因此您需要确定保留哪个。选择较旧的版本可能会解决一个编译错误,但会导致另一个:-)

默认情况下,ivy将在假定其向后兼容的情况下选择最新版本。您可以通过使用冲突指示器来覆盖此行为,如下所示:

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


 类似资料:
  • 我的结构如下: 项目A- 项目B- 编译项目B一切正常: 项目B/build.gradle: ProjectB/settings.gradle: 然而,在编译ProjectA时,它表示找不到ProjectC ProjectA/build.gradle: ProjectA/settings.gradle: 这将显示以下错误: 其中:构建文件ProjectB\build.gradle 出了什么问题:

  • 编写的PHP扩展需要需要依赖另外一个扩展,在PHP-X中可以调用Extension->require来实现。 PHPX_EXTENSION() { Extension *ext = new Extension("test", "0.0.1"); ext->require("swoole"); ext->require("sockets"); return ext;

  • 依赖关系 这是一个非常轻量级的模块,没有其他依赖项。希望大家在JVM或Android上使用以太坊的RLP编码的项目时会选择使用这个模块,而不再编写自己的实现。

  • 依赖关系 ABI一个非常轻量级的模块,唯一的第三方依赖是 Bouncy Castle,用于hash加密 (Spongy Castle on Android)。 最后希望java和安卓开发者,在JVM或Android上有以太坊ABI合作的项目时会选择使用这个模块,而不是再编写自己的实现。

  • 问题内容: 我有一个依赖关系如下: 当我部署一切正常时,这将拉下另一个引发ClassDefNotFound的依赖项。 我添加了两个依赖项,如下所示: 并且仍然面临着同样的问题,即:MVN带来下来不 我该如何解决? 编辑: 添加; 问题答案: 您可能有一个传递依赖项,另一个依赖项取决于您不需要的版本。 要获得所有直接和传递依赖关系的概述,请尝试: mvn依赖项:树 如果您发现同一依赖项的不同版本之间

  • 问题内容: 假设我有四个项目: 项目A(依赖于B和D) 项目B(依赖于D) 项目C(依赖于D) 项目D 在这种情况下,如果我运行项目A,则Maven将正确地解决对D的依赖关系。如果我理解正确,则Maven始终以最短的路径获取依赖关系。由于D是A的直接依赖项,因此将使用B内指定的D而不是D。 但是现在假设这种结构: 项目A(依赖于B和C) 项目B(依赖于D) 项目C(依赖于D) 项目D 在这种情况下