maven引入log4j、slf4j冲突,java.…

tomcat启动报错: java.lang.LinkageError:loader constraint violation: when resolving method"org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;"the class loader (instance oforg/apache/catalina/loader/WebappClassLoader) of the current class,org/slf4j/LoggerFactory, and the class loader (instance of forresolved class, org/slf4j/impl/StaticLoggerBinder, have differentClass objects for the type LoggerFactory; used in thesignature
原因是tomcat自带的lib下已经有了log4j、slf4j的jar包,修改项目这几个依赖的scope为 provided 即可。
maven依赖的scope默认是compile
compile表示被依赖项目需要参与当前项目的编译, 参与test、runtime,是一个比较强的依赖。而修改为 provided意味着打包的时候可以不用包进去,运行时JDK或容器(如tomcat )会提供。
scope的官方文档解释如下:
scope :
This element refers to the classpath of the task at hand (compilingand runtime, testing, etc.) as well as how to limit thetransitivity of a dependency. There are five scopesavailable:
  • compile - this is the default scope,used if none is specified. Compile dependencies are available inall classpaths. Furthermore, those dependencies are propagated todependent projects.
  • provided - this is much like compile,but indicates you expect the JDK or a container to provide it atruntime. It is only available on the compilation and testclasspath, and is not transitive.
  • runtime - this scope indicates that thedependency is not required for compilation, but is for execution.It is in the runtime and test classpaths, but not the compileclasspath.
  • test - this scope indicates that thedependency is not required for normal use of the application, andis only available for the test compilation and execution phases. Itis not transitive.
  • system - this scope is similarto provided exceptthat you have to provide the JAR which contains it explicitly. Theartifact is always available and is not looked up in arepository.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值