问题描述:学习 Hibernate持久化技术时,使用hibernate
-
annotations
-
3.4
.
0
.GA版本做实验,做好了程序和配置文件后,运行程序出现
java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from
class
org.slf4j.LoggerFactory错误。
问题原因:jar文件版本冲突
类 org.slf4j.impl.StaticLoggerBinder在slf4j - api 中是类的公有静态变量:
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
而在slf4j - log4j12(slf4j - nop.jar, slf4j - simple.jar, slf4j - log4j12.jar, slf4j - jdk14.jar or logback - classic.jar其中之一)中确是私有变量:
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
解决方案: 1 .修改slf的源代码,将这个变量有私有改为公有,再打包,问题可解决。
2 .在类路径先将slf4j - api.jar 删除,再导入同版本的slf4j - api - 1.5 . 6 .jar 和slf4j - log4j12 - 1.5 . 6 .jar ,问题可解决。
问题原因:jar文件版本冲突
类 org.slf4j.impl.StaticLoggerBinder在slf4j - api 中是类的公有静态变量:
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
以上是在网络上找的答案,也有很多人试过的,但是我遇到这个问题时,使用的Hibernate是3.6的,这种方法不适合。
后来我将 hibernate - jpa - 2.0 - api - 1.0 . 0 .Final.jar 包也加了进来之后,程序就好了。具体原因还在纠结
.
后来我将 hibernate - jpa - 2.0 - api - 1.0 . 0 .Final.jar 包也加了进来之后,程序就好了。具体原因还在纠结

而在slf4j - log4j12(slf4j - nop.jar, slf4j - simple.jar, slf4j - log4j12.jar, slf4j - jdk14.jar or logback - classic.jar其中之一)中确是私有变量:
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
解决方案: 1 .修改slf的源代码,将这个变量有私有改为公有,再打包,问题可解决。
2 .在类路径先将slf4j - api.jar 删除,再导入同版本的slf4j - api - 1.5 . 6 .jar 和slf4j - log4j12 - 1.5 . 6 .jar ,问题可解决。
我遇到这个问题时用的是Hibernate3.6,是将hibernate-jpa-2.0-api-1.0.0.Final.jar包加进去才解决了的。相同问题的朋友试试。