开发者社区> 问答> 正文

hibernate框架中一个问题,实现添加数据报错?报错

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:20)
at com.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
at com.pb.hibernate.test.Test.main(Test.java:15)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:15)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more

展开
收起
爱吃鱼的程序员 2020-06-22 22:55:48 768 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    你日志接口用的是slf4j,底层日志实现用的是log4j,根据slf4j的规定,你需要一个slf4j到log4j的转换jar包

    回复 @追逐梦想:我回答的是针对的第一个错误,但你已经加了slf4j-nop-1.5.2.jar,就不需要加slf4j-log4j12-1.5.8.jar我下载添加了你说的那个slf4j-log4j12-1.5.8.jar出现了下面的情况。。。又出现错误了.... java.lang.ClassNotFoundException:org.slf4j.impl.StaticLoggerBinder 帮我看看...怎么解决啊?缺包,slf.lar,或者工程发部有问题

    缺少 slf4j-nop-1.5.2.jar包,导入即可。


    下载地址:

    http://download.csdn.net/detail/jianfan_k/3545292

    http://ishare.iask.sina.com.cn/f/11298521.html?retcode=0

    看一下新的错误InitialSessionFactorycreationfailed.org.hibernate.InvalidMappingException:Couldnotparsemappingdocumentfromresourcecom/pb/hibernate/po/Login.hbm.xml
    Exceptioninthread"main"java.lang.ExceptionInInitializerError
    atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:20)
    atcom.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
    atcom.pb.hibernate.test.Test.main(Test.java:15)
    Causedby:org.hibernate.InvalidMappingException:Couldnotparsemappingdocumentfromresourcecom/pb/hibernate/po/Login.hbm.xml
    atorg.hibernate.cfg.Configuration.addResource(Configuration.java:616)
    atorg.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
    atorg.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
    atorg.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
    atorg.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
    atorg.hibernate.cfg.Configuration.configure(Configuration.java:1476)
    atorg.hibernate.cfg.Configuration.configure(Configuration.java:1462)
    atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
    ...2more
    Causedby:org.hibernate.InvalidMappingException:Couldnotparsemappingdocumentfrominputstream
    atorg.hibernate.cfg.Configuration.addInputStream(Configuration.java:555)
    atorg.hibernate.cfg.Configuration.addResource(Configuration.java:613)
    ...9more
    Causedby:org.dom4j.DocumentException:Erroronline15ofdocument :元素类型"class"必须由匹配的结束标记"</class>"终止。Nestedexception:元素类型"class"必须由匹配的结束标记"</class>"终止。
    atorg.dom4j.io.SAXReader.read(SAXReader.java:482)
    atorg.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)
    ...10more

    大家帮帮我啦。。。 SLF4J:ClasspathcontainsmultipleSLF4Jbindings.
    SLF4J:Foundbindingin[jar:file:/C:/Users/supermanxkq/Desktop/slf4j-nop-1.5.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J:Foundbindingin[jar:file:/C:/Users/supermanxkq/Desktop/slf4j-log4j12-1.5.8%20(1).jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J:See http://www.slf4j.org/codes.html#multiple_bindingsforanexplanation.
    InitialSessionFactorycreationfailed.org.hibernate.MappingNotFoundException:resource:com/pb/hibernate/po/Login/hbm/xmlnotfound
    Exceptioninthread"main"java.lang.ExceptionInInitializerError
     atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
     atcom.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
     atcom.pb.hibernate.test.Test.main(Test.java:15)
    Causedby:org.hibernate.MappingNotFoundException:resource:com/pb/hibernate/po/Login/hbm/xmlnotfound
     atorg.hibernate.cfg.Configuration.addResource(Configuration.java:610)
     atorg.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
     atorg.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
     atorg.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
     atorg.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
     atorg.hibernate.cfg.Configuration.configure(Configuration.java:1476)
     atorg.hibernate.cfg.Configuration.configure(Configuration.java:1462)
     atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
     ...2more

    无效的配置文件,你的Login.hbm.xml配置有错吧

    回复 @追逐梦想:可能是数据库版本、jdbc驱动、方言配置等没有匹配嗯,我的login.hbm.xml在hibernate.cfg.xml中指定映射文件的完整路径的时候写成了login/hbm/xml,然后改过来之后又出现了这个问题。。。 log4j:WARNNoappenderscouldbefoundforlogger(org.hibernate.cfg.Environment).
    log4j:WARNPleaseinitializethelog4jsystemproperly.
    log4j:WARNSee http://logging.apache.org/log4j/1.2/faq.html#noconfigformoreinfo.
    InitialSessionFactorycreationfailed.org.hibernate.HibernateException:Unabletoaccessjava.sql.DatabaseMetaDatatodetermineappropriateDialecttouse
    Exceptioninthread"main"java.lang.ExceptionInInitializerError
     atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
     atcom.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
     atcom.pb.hibernate.test.Test.main(Test.java:15)
    Causedby:org.hibernate.HibernateException:Unabletoaccessjava.sql.DatabaseMetaDatatodetermineappropriateDialecttouse
     atorg.hibernate.dialect.resolver.DialectFactory.determineDialect(DialectFactory.java:141)
     atorg.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:97)
     atorg.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:117)
     atorg.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
     atorg.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
     atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
     atcom.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
     ...2more
    Causedby:java.sql.SQLException:不支持的特性
     atoracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
     atoracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
     atoracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
     atoracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)
     atoracle.jdbc.OracleDatabaseMetaData.getDatabaseMajorVersion(OracleDatabaseMetaData.java:4442)
     atorg.hibernate.dialect.resolver.DialectFactory.determineDialect(DialectFactory.java:131)
     ...8more
    2020-06-22 22:56:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载