2017-02-16 112 views
0

我收到以下错误:LinkageError类 - 装载机约束冲突 - 解决方法时, “org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()”

ContextListenerjava.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader '[email protected] (urls: ['], parents: [)'[email protected]']) of the current class, org/slf4j/LoggerFactory, and the class loader 'System (urls: [''file:/usr/lib/jvm/jvm_8/jvm_8/lib/jvmx.jar', 'file:/usr/lib/jvm/jvm_8/jvm_8/lib/tools.jar', 'file:/ ....

它通过默认包slf4j看来我的云平台,我得到这个错误,因为我也把slf4j作为依赖在我的pom文件和两个不同的类加载器正在加载slf4j

我解决这个问题的方式是改变在POM依赖项的范围提供。

但副作用是我无法在我的本地tomcat上运行它,因为它找不到slf4j库。

在这种情况下可以做些什么,这样我的战争在我的云平台和我的本地tomcat上运行良好?

回答

0

你可以在你的pom.xml中使用不同的配置文件。

举例SAP云平台:

<profiles> 
     <profile> 
      <id>local</id> 
      <properties> 
       <packaging.type>jar</packaging.type> 
      </properties> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <dependencies> 
       <dependency> 
        <groupId>com.h2database</groupId> 
        <artifactId>h2</artifactId> 
       </dependency> 
      </dependencies> 
     </profile> 
    <profile> 
     <id>scp</id> 
     <properties> 
      <packaging.type>war</packaging.type> 
     </properties> 
     <build> 
      <finalName>LoraConnector</finalName> 
     </build> 
     <activation> 
      <activeByDefault>false</activeByDefault> 
     </activation> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-logging</artifactId> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-api</artifactId> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>org.slf4j</groupId> 
       <artifactId>jul-to-slf4j</artifactId> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-tomcat</artifactId> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>com.h2database</groupId> 
       <artifactId>h2</artifactId> 
       <scope>test</scope> 
      </dependency> 
     </dependencies> 
    </profile> 
</profiles> 

您可以在Eclipse中使用 “运行配置” 使用配置文件(或其他工具),或者当你建立war文件:

mvn -P scp clean package 
0

如果您使用的是spring-boot-starter-web-1.5.1.RELEASE.jar,那么您需要排除jul-to-slf4j-1.7.22.jar,jcl-over-slf4j-1.7.22.jar。这两个jar有冲突slf4j-api。 <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <packagingExcludes> WEB-INF/lib/jcl-over-slf4j-1.7.22.jar,WEB-INF/lib/jul-to-slf4j-1.7.22.jar </packagingExcludes> </configuration> </plugin>