Hibernate-annotations 3.4.0.GA 和 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。在项目 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不建议这样做,您应该使用相同版本的 slf4j 工件。来自常见问题解答:
这是需要解决的问题。
问题是,您从 B 获得 SLF4J 工件 并从 A 获得 工件(传递性地),因此您最终会混合 >
slf4j-api
的多个版本(1.5.5 和 1.6.1)和多个绑定(slf4j-log4j12
和logback-classic
)。 SLF4J 在运行时抱怨后面的问题,但您应该修复这两个问题。是的,该消息建议将绑定升级到更新版本。但是,更重要的是,它报告您在类路径上有多个 ONE 绑定:您需要在 log4j 和 logback 之间进行选择作为日志支持,并提供适当的绑定,但不能同时提供两者。
要严格回答有关控制传递依赖项中的版本的问题,可以使用
dependencyManagement
元素来完成。这是一个示例:并且具有
slf4j-api
作为依赖项的工件(例如 Hibernate EntityManager)将使用版本 1.6.1,如下所示:但正如我所说,真正的问题是您需要类路径上只有一个绑定。选择 log4j 或 logback,但不能同时选择两者,并提供适当的绑定。
That's not recommended, you should use the same versions of slf4j artifacts. From the FAQ:
That's something to fix.
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
andlogback-classic
). SLF4J is complaining about the later problem at runtime but you should fix both.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.
To strictly answer this question about controlling versions in transitive dependencies, this can be done using the
dependencyManagement
element. Here is an example:And artifacts having
slf4j-api
as dependency, such as Hibernate EntityManager, would use version 1.6.1 as shown below: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.
我遇到了这个问题,但在爬行我的依赖树并修复我的 pom 后,我仍然遇到问题。我的解决方案?
(以防万一其他人犯了我的错误!)
I had this problem but after crawling my dependency tree and fixing my pom I was still having issues. My solution?
(just in case anyone else made my mistake!)