Hibernate-annotations 3.4.0.GA 和 slf4j?

发布于 2024-09-15 22:45:17 字数 1165 浏览 11 评论 0原文

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

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

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 中的绑定升级到 1.6.x,但我不明白这是如何可能的,因为它包含在休眠中依赖性。

运行项目 B 时是否可以切换绑定(更新类路径信息),以便它使用 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.

I have another maven project B which depend on project A. In project B I have specified the following dependencies:

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

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

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很糊涂小朋友 2024-09-22 22:45:17

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

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

SLF4J 版本向后兼容吗?

除了极少数理论上的例外,
SLF4J版本落后
兼容的。这意味着你可以
从 SLF4J 版本 1.0 升级到任何版本
更高版本没有问题。

但是,虽然 SLF4J API 非常
从客户的角度来看稳定,
SLF4J 绑定,例如 slf4j-simple 或
slf4j-log4j12 可能需要特定的
slf4j-api 的版本。 混合
不同版本的 slf4j 工件
可能会出现问题并且强烈
气馁。
例如,如果您
正在使用 slf4j-api-1.5.6.jar,那么
你还应该使用
slf4j-simple-1.5.6.jar,使用
slf4j-simple-1.4.2.jar 将无法工作。

初始化时,如果是SLF4J
怀疑可能有版本
不匹配问题,它会发出警告
关于所说的不匹配。对于确切的
版本不匹配的详细信息
检测机制,请参考
此常见问题解答中的相关条目

这是需要解决的问题。

它可以从命令行使用 Maven 构建良好的版本。但是当我从 eclipse 启动配置运行项目时,我得到 (...)

问题是,您从 B 获得 SLF4J 工件 并从 A 获得 工件(传递性地),因此您最终会混合 >slf4j-api 的多个版本(1.5.5 和 1.6.1)和多个绑定slf4j-log4j12logback-classic)。 SLF4J 在运行时抱怨后面的问题,但您应该修复这两个问题。

从此消息表明我需要将项目 A 中的绑定升级到 1.6.x,但我不知道这是如何实现的,因为它包含在 hibernate 依赖项中。

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

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

要严格回答有关控制传递依赖项中的版本的问题,可以使用 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 dependency:tree
...
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[INFO] |  +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[INFO] |  +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- javax.transaction:jta:jar:1.1:compile
[INFO] |  \- javassist:javassist:jar:3.4.GA:compile

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

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.

That's not recommended, you should use the same versions of slf4j artifacts. From the FAQ:

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.

That's something to fix.

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

The problem is that you get the SLF4J artifacts from B and those from A (transitively) and you thus end up mixing several versions of the slf4j-api (1.5.5 and 1.6.1) and several bindings (slf4j-log4j12 and logback-classic). SLF4J is complaining about the later problem at runtime but you should fix both.

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.

Yes, the message suggests upgrading a binding to a more recent version. But, more important, it reports that you have more than ONE binding on the class path: you need to choose between log4j and logback as logging backed and to provide the appropriate binding, but not both of them.

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?

To strictly answer this question about controlling versions in transitive dependencies, this can be done using the dependencyManagement element. Here is an example:

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

And artifacts having slf4j-api as dependency, such as Hibernate EntityManager, would use version 1.6.1 as shown below:

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

But as I said, the real problem is that you need to have only one binding on the classpath. Either choose log4j or logback, just not both, and provide the appropriate binding.

弃爱 2024-09-22 22:45:17

我遇到了这个问题,但在爬行我的依赖树并修复我的 pom 后,我仍然遇到问题。我的解决方案?

mvn clean

(以防万一其他人犯了我的错误!)

I had this problem but after crawling my dependency tree and fixing my pom I was still having issues. My solution?

mvn clean

(just in case anyone else made my mistake!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文