码迷,mamicode.com
首页 > 数据库 > 详细

java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory

时间:2017-05-16 14:50:30      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:运行程序   img   版本   jar包   execution   children   ati   family   singleton   

 一、问题描述:

搭建hibernate环境时,使用hibernate-distribution-3.3.1.GA-dist和slf4j-1.7.7。配置文件和程序OK之后,运行程序出现如下问题:

 1 java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
 2     at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
 3     at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
 4     at com.pers.test.CustomerTest.<clinit>(CustomerTest.java:33)
 5     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 6     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 7     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 8     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 9     at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
10     at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
11     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
12     at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
13     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
14     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
15     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
16     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
17     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
18     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
19     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
20     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
21     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
22     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
23     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
24     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
25     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
26     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

 

二、原因分析:jar包版本冲突

类 org.slf4j.impl.StaticLoggerBinder在hibernate-distribution-3.3.1.GA-dist\hibernate-distribution-3.3.1.GA\lib\required\slf4j-api-1.5.2.jar中是类的公有静态变量: 

public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

而在slf4j-1.7.7\slf4j-log4j12-1.7.7.jar中是私有变量: 

private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

解决方案:1.修改slf的源代码,将这个变量由私有改为公有,再打包,问题可解决。

                 2. 将slf4j-api-1.5.2.jar替换为slf4j-1.7.7\slf4j-api-1.7.7.jar,问题可解决。

 

三、jar包附图

技术分享

  如果需要注解或和其他框架整合,则另行导入,各jar作用不再赘述。

 

java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory

标签:运行程序   img   版本   jar包   execution   children   ati   family   singleton   

原文地址:http://www.cnblogs.com/yadongliang/p/6860884.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!