slf4j jar包冲突解决方案

国外原文地址 :点击打开链接

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
	at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:305)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

今天碰到的问题,项目中不同的两个jar包分别依赖了相同的一个jar包的不同版本,造成冲突。

解释:就是说项目中要用到某一个a.jar包,通过maven引入了之后,也自动的导入了该jar包所依赖的包,这里就会存在一个问题,如果a.jar包依赖b.jar这个项目的1.0版本,可是我的项目中已经有b.jar这个项目2.0的版本了,这里就会造成冲突,解决的办法是去除a.jar包依赖b.jar这个项目的1.0版本的依赖关系,让项目使用我已有的包。


You are mixing the 1.5.6 version of the jcl bridge with the 1.6.0 version of the slf4j-api; this won't work because of a few changes in 1.6.0. Use the same versions for both, i.e. 1.6.1 (the latest). I use the jcl-over-slf4j bridge all the time and it works fine.

这给了我启发

我的项目中用到了2个不同版本的slf4j-api,而其中一个是1.5.8版本,另一个是1.7.6版。



This can be caused when a dependent library has accidentally bundled an old version of slf4j. 

The work around is exclude the component and then manually depend on the correct or patched version.


造成这种情况的原因上面已经说过,分别由2个不同的jar包分别依赖了不同版本的slf4j,而该jar包的1.6.0版本对其中一个方法做了改动,所以1.6.0以前的版本和1.6.0以后

的版本会造成编译错误。

SLF4J 1.5.11 and 1.6.0 versions are not compatible (see compatibility report) because the argument list of org.slf4j.spi.LocationAwareLogger.log method has been changed (added Object[] p5):

版本改动具体如下

//SLF4J 1.5.11:
LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
                          String p4, Throwable p5 )

//SLF4J 1.6.0:
LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
                          String p4, Object[] p5, Throwable p6 )


解决方案

首先要找出冲突的jar包的依赖关系,用我的项目举例,我的pom里引入了 FCKeditor.Java Integration Core 2.6

其依赖于slf4j.api 1.5.8 (依赖关系可在http://mvnrepository.com/ 找到)

找出依赖关系后只需要解除其依赖关系即可。



   
   

   
   
	
    
    
     
     net.fckeditor
    
    
	
    
    
     
     java-core
    
    
	
    
    
     
     2.6
    
    

   
   


   
   

   
   
	
    
    
     
     net.fckeditor
    
    
	
    
    
     
     java-core
    
    
	
    
    
     
     2.6
    
    
	
    
    
		
    
    
		  
     
     
			
      
      
       
       org.slf4j
      
      
            
      
      
       
       slf4j-api
      
      
		  
     
     
	    
    
    

   
   

去掉了旧版本的依赖后,就不会报错了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值