SLF4J version conflict

本文介绍了一个关于SLF4J非法访问错误的问题,该问题发生在使用旧版slf4j-api与新版SLF4J绑定时。文章详细解释了错误产生的原因,并提供了检查依赖版本及解决此问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Here are the exception details.

Exception in thread "main" java.lang.IllegalAccessError: tried to access field
org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
   at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)

This error is caused by the static initilizer of the LoggerFactory class attempting to directly access the SINGLETON field oforg.slf4j.impl.StaticLoggerBinder. While this was allowed in SLF4J 1.5.5 and earlier, in 1.5.6 and later the SINGLETON field has been marked as private access.

If you get the exception shown above, then you are using an older version of slf4j-api, e.g. 1.4.3, with a new version of a slf4j binding, e.g. 1.5.6. Typically, this occurs when your Maven pom.ml file incoprporates hibernate 3.3.0 which declares a dependency on slf4j-api version 1.4.2. If yourpom.xml declares a dependency on an slf4j binding, say slf4j-log4j12 version 1.5.6, then you will get illegal access errors.

To see which version of slfj4-api is pulled in by Maven, use the maven dependency plugin as follows.

mvn dependency:tree

If you are usig Eclipse, please do not rely on the dependency tree shown by m2eclipse.

In your pom.xml file, excplicitly declaring a dependecy on slf4j-api matching the version of the declared binding will make the problem go away.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值