【问题标题】:Forcing maven spring boot project to use older version of a dependency instead of a new version from another dependency强制 maven spring boot 项目使用旧版本的依赖而不是来自另一个依赖的新版本
【发布时间】:2017-01-05 19:43:49
【问题描述】:

由于此问题中列出的相同问题,我遇到了无法启动 Spring Boot 服务器的问题:

How to set up Spring Boot and log4j2 properly?

我遇到这种情况是因为spring boot项目依赖于一个包含elasticsearch的jar,其中包含了一个与spring boot不兼容的新版本slf4j

我通过在 elasticsearch 项目依赖项定义中实现每个排除项来尝试推荐的解决方案,但由于某种原因,新版本不断被采用。我似乎无法强制 spring boot 项目忽略 elasticsearch 项目使用的日志记录包。

这是我的 spring-boot 项目的 pom,请参阅 Problems.project.import 的依赖项:http://pastebin.com/Yeq2qk9Y

这里是正在导入到 spring boot 项目中的项目的 pom:http://pastebin.com/gknmf6Tt

我得到的错误是:

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:165)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadDefaults(Log4J2LoggingSystem.java:148)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:75)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)

关于如何解决此问题的任何提示?这是否可以加载这组库的两个版本,每个模块都不知道他们不需要的版本?

【问题讨论】:

标签: java maven spring-boot log4j log4j2


【解决方案1】:

您可以通过在pom.xml 中使用<exclusions> 标记来排除循环依赖项,如下所示:

<dependency>
  <groupId>sample.ProjectB</groupId>
  <artifactId>Project-B</artifactId>
  <version>1.0-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
      <artifactId>Project-E</artifactId>
    </exclusion>
  </exclusions>
</dependency>

您应该从拥有它的依赖项中排除新版本的循环依赖项,这样只会加载旧版本,而不是同时加载两者。

这里是更多信息的链接:

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

【讨论】:

  • 我相信我正在这样做。你能看看poms吗?我这样做对吗?
猜你喜欢
  • 1970-01-01
  • 2017-07-17
  • 2020-03-29
  • 2014-10-13
  • 2019-12-23
  • 1970-01-01
  • 2016-09-18
  • 1970-01-01
  • 2021-12-30
相关资源
最近更新 更多