slf4j-log4j13 和 slf4j-log4j12 之间的冲突

发布于 2024-09-25 14:27:03 字数 1768 浏览 5 评论 0原文

我的 Maven 依赖项中包含 slf4j 1.6.1 和 Log4j 1.2.16。在以前的项目中它曾经工作得很好。然而,最近我通过重用以前的一些代码库开始了一个新项目,然后我开始遇到一些奇怪的问题。

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>

<dependency>
  <groupId>org.apache.solr</groupId>
  <artifactId>solr-solrj</artifactId>
  <version>1.4.1</version>
</dependency>

基本上发生的事情是,slf4j-log4j13 也以某种方式包含在 war 文件中,很可能是通过一些其他依赖项的传递依赖关系。但是,当我使用“mvn dependency:tree”检查传递依赖项时,我没有找到“slf4j-log4j13”。

结果很棘手。我的 war 文件中有 slf4j-log4j12 和 slf4j-log4j13 。令人惊讶的是,它在我的 Mac OSX 系统上运行得很好。工作正常是指不存在由此引起的任何冲突、异常或错误。然而,当我将它部署到另一台Linux(Ubuntu)64位机器上时,却给我带来了麻烦。异常如下,

'xmlResponseParser' while setting bean property 'parser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlResponseParser' defined in ServletContext resource [/WEB-INF/spring/spring-solr.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.apache.log4j.Logger.log(Ljava/lang/String;Lorg/apache/log4j/Level;Ljava/lang/Object;Ljava/lang/Throwable;)V
(Stack trace ignored)

看起来 xmlResponseParser 正在使用 slf4j 但找不到 log4j 依赖项。这是slf4j-log4j12和slf4j-log413冲突造成的吗?为什么只有 Linux 上才会出现这种情况?

我试图删除其中之一;然而,删除其中任何一个都会导致问题。我想看看有没有人有类似经历。

I have slf4j 1.6.1 with Log4j 1.2.16 included in my maven depedencies. It used to work fine in previous projects. However, recently I started a new project by reusing some of the previous code base, and then I started to have some weird issues.

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>

<dependency>
  <groupId>org.apache.solr</groupId>
  <artifactId>solr-solrj</artifactId>
  <version>1.4.1</version>
</dependency>

Basically what happened is that somehow slf4j-log4j13 is also included into the war file, most likely thru some transitive dependency relationships of some other dependencies. However, when I used "mvn dependency:tree" to check the transitive dependencies, I didn't find "slf4j-log4j13".

The result is tricky. I have both slf4j-log4j12 and slf4j-log4j13 in my war file. Surprisingly it worked fine on my Mac OSX system, somehow. By working fine, I mean there are no any conflicts, exceptions or errors caused by it. However, when I deploy it to another Linux (Ubuntu) 64-bit machine, it gave me troubles. The exception is as follows,

'xmlResponseParser' while setting bean property 'parser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlResponseParser' defined in ServletContext resource [/WEB-INF/spring/spring-solr.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.apache.log4j.Logger.log(Ljava/lang/String;Lorg/apache/log4j/Level;Ljava/lang/Object;Ljava/lang/Throwable;)V
(Stack trace ignored)

Looks like xmlResponseParser is using slf4j but could not find log4j dependency. Is this caused by the conflicts between slf4j-log4j12 and slf4j-log413? Why does it happen only on Linux?

I tried to remove one of them; however, removing either of them causes problems. I'd like to see if anyone had similar experiences.

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

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

发布评论

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

评论(1

甜中书 2024-10-02 14:27:03

问题解决了。 slf4j-log4j13 静态包含在 webapp/WEB-INF/lib 中,不直接由 maven 管理。

problem solved. slf4j-log4j13 is included statically in webapp/WEB-INF/lib, not directly managed by maven.

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