Messages: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory 
 
File: org/slf4j/LoggerFactory.java 
  上网查了下 说使用hbm2java时,使用hibernate-distribution-3.3.1.GA-dist版本,做好了程序和配置文件后,运行程序出现Exception in thread "main" 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 ,问题可解决。但是我工程里面加了  slf4j-api-1.5.8.jar  slf4j-log4j12-1.5.8.jar  log4j-1.2.15.jar  还是抛错 Hibernate是3.2版还有个问题就是:执行 SessionFactory sf=helpclass.getsf();
Session s=sf.getCurrentSession();
s.beginTransaction();
Users u=new Users();
u.setUser_name("tan");
u.setUser_pwd("tan");
List list=getquery(u);

System.out.println(list.size());
s.getTransaction().commit();
也出了错:
org.hibernate.SessionException: Session is closed!??
public class helpclass {
private static  SessionFactory sf;
static {
sf=new AnnotationConfiguration().configure().buildSessionFactory();
}
public static SessionFactory getsf(){
return sf;
}
}

解决方案 »

  1.   

    org.hibernate.SessionException: Session is closed!??
    session 关闭了嘛,
    Session s=sf.getCurrentSession();
    你这里用的是getCurrentSession
    getCurrentSession和getSession是用区别的,
    getCurrentSession不会去创建一个session,它在事务结束后就自动关闭了
    getSession会去创建一个session,它需要手动关闭
      

  2.   

    还不是不明白 ! 我用的是 getCurrentSession 既然可以自动关闭 那为什么还会报错捏!!???
      

  3.   

    整合最容易出来就的是问题就是包冲突,
    你检查一下lib下面有版本不同的但同名的删掉啦。。
      

  4.   

    List list=getquery(u);这里的代码是啥,发出来看看
      

  5.   

     大家看看这个咯!!
    Messages: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory  
     
    File: org/slf4j/LoggerFactory.java  
      上网查了下 说使用hbm2java时,使用hibernate-distribution-3.3.1.GA-dist版本,做好了程序和配置文件后,运行程序出现Exception in thread "main" 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 ,问题可解决。但是我工程里面加了 slf4j-api-1.5.8.jar slf4j-log4j12-1.5.8.jar log4j-1.2.15.jar 还是抛错 Hibernate是3.2版