eclipse - Hibernate-annotations 3.4.0.GA 和 slf4j?

标签 eclipse hibernate maven-2 slf4j

我有一个使用 hibernate-annotations 3.4.0.GA 的 maven 项目 A,它使用 slf4j-api 版本 1.5.5(通过 pom.xml 文件中的依赖关系树检查)。进一步的项目 A 将 slf4j-log4j12 版本 1.4.2 指定为依赖项。

我有另一个依赖于项目 A 的 Maven 项目 B。在项目 B 中,我指定了以下依赖项:

slf4j-api version 1.6.1,
logback-core version 0.9.24
logback-classic version 0.9.24

从命令行使用 maven 构建良好。但是当我从 Eclipse 启动配置运行项目时,我得到:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x

从这条消息中它表明我需要将项目 A 中的绑定(bind)升级到 1.6.x,但我不知道这是怎么可能的,因为它包含在 hibernate 依赖项中。

运行项目 B 时是否可以切换绑定(bind)(更新类路径信息),以便它使用 1.6.1 版本而不是 hibernate 项目中的版本?

最佳答案

I have a maven project A that use hibernate-annotations 3.4.0.GA which use the slf4j-api version 1.5.5 (checked through the dependency tree in the pom.xml file). Further project A specifies slf4j-log4j12 version 1.4.2 as a dependency.



不建议这样做,您应该使用相同版本的 slf4j 工件。从常见问题解答:

Are SLF4J versions backward compatible?

With rare theoretical exceptions, SLF4J versions are backward compatible. This means than you can upgrade from SLF4J version 1.0 to any later version without problems.

However, while the SLF4J API is very stable from the client's perspective, SLF4J bindings such as slf4j-simple or slf4j-log4j12 may require a specific version of slf4j-api. Mixing different versions of slf4j artifacts can be problematic and is strongly discouraged. For instance, if you are using slf4j-api-1.5.6.jar, then you should also use slf4j-simple-1.5.6.jar, using slf4j-simple-1.4.2.jar will not work.

At initialization time, if SLF4J suspects that there may be a version mismatch problem, it emits a warning about the said mismatch. For the exact details of the version mismatch detection mechanism, please refer to the relevant entry in this FAQ.



这是要解决的问题。

which builds fine with maven from the command line. But when I run the project from eclipse launch configuration I get (...)



问题是您从 B 获得 SLF4J 工件和 来自 A 的那些(及物),因此你最终混合了 slf4j-api 的几个版本 (1.5.5 和 1.6.1)和 几个绑定(bind) ( slf4j-log4j12logback-classic )。 SLF4J 在运行时提示后面的问题,但您应该同时修复这两个问题。

From this message its indicated to that I need to upgrade the binding in project A to 1.6.x, but I don't see how that is possible since its included in the hibernate dependency.



是的,该消息建议将绑定(bind)升级到更新的版本。但是,更重要的是,它报告您拥有超过 一个 类路径上的绑定(bind):您需要在 log4j 和 logback 之间选择作为日志支持并提供适当的绑定(bind),但不能同时提供两者。

Is it possible to switch the binding (updating the classpath info) when running project B so it use the 1.6.1 version instead of the version from the hibernate project?



要严格回答有关在传递依赖中控制版本的问题,可以使用 dependencyManagement 来完成。元素。这是一个例子:
<project>
  ...
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  ...
  <dependencies>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.4.0.GA</version>
    </dependency>
  </dependencies>
  ...
</project>

以及具有 slf4j-api 的工件作为依赖项,例如 Hibernate EntityManager,将使用 1.6.1 版本,如下所示:

$ mvn 依赖:树
...
[信息] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[信息] | +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[信息] | +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[信息] | +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[信息] | +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
[信息] | | +- antlr:antlr:jar:2.7.6:compile
[信息] | |\- commons-collections:commons-collections:jar:3.1:compile
[信息] | +- org.slf4j:slf4j-api:jar:1.6.1:compile
[信息] | +- dom4j:dom4j:jar:1.6.1:编译
[信息] | |\- xml-apis:xml-apis:jar:1.0.b2:compile
[信息] | +- javax.transaction:jta:jar:1.1:compile
[信息] |\- javassist:javassist:jar:3.4.GA:compile

但正如我所说,真正的问题是您只需要在类路径上有一个绑定(bind)。选择 log4j 或 logback,而不是两者,并提供适当的绑定(bind)。

关于eclipse - Hibernate-annotations 3.4.0.GA 和 slf4j?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3546911/

相关文章:

java - 如何让 "master"之外的其他分支显示在我的包资源管理器中?

linux - 使用旧功能和插件的新 eclipse 安装

java - 使用Spring hibernate mongodb进行审计

java - 将 3rd 方库安装到托管的 Maven 存储库中的最佳实践?

java - 如何为 Maven 中的某些依赖项定义不同的目标文件夹

java - 如何在 Eclipse 中从一个项目中跳转到另一个项目中的类型声明(实现)?

java - Eclipse 内存分析器说明

java - Spring MVC : correct package for POJO used in services

postgresql - Hibernate 与分区表

java - 为什么很多 Maven 依赖版本都以 SNAPSHOT 结尾?