hibernate出現Exception in thread "main " java.lang.ExceptionInInitializerError錯誤解決辦法
阿新 • • 發佈:2019-01-05
最近複習了下hibernate的內容,用於準備面試。另外看了下尚學堂的視訊,按照步驟去做了幾個實驗,
但是在這過程中遇到了以下錯誤問題:
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/Jar%20Package/slf4j-1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/Jar%20Package/slf4j-1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. Exception in thread "main" java.lang.ExceptionInInitializerError at org.hibernate.cfg.Configuration.reset(Configuration.java:217) at org.hibernate.cfg.AnnotationConfiguration.reset(AnnotationConfiguration.java:233) at org.hibernate.cfg.Configuration.<init>(Configuration.java:197) at org.hibernate.cfg.Configuration.<init>(Configuration.java:201) at org.hibernate.cfg.AnnotationConfiguration.<init>(AnnotationConfiguration.java:108) at com.bjsxt.hibernate.HibernateQLTest.beforeClass(HibernateQLTest.java:21) at com.bjsxt.hibernate.HibernateQLTest.main(HibernateQLTest.java:367) Caused by: java.lang.NullPointerException at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167) at org.hibernate.cfg.Environment.<clinit>(Environment.java:575) ... 7 more
後經網上查詢,原因在於自己在eclipse中增加user library的時候有個複選框"System libary(added to the boot class path)",這個東西不要勾上了,我就是把這個勾上了所以就不行了。以上你要排除你正確的匯入了所有必須的包。
以上解決問題方法來自於csdn一位朋友的回帖,非常感謝。
另外在該問題出現之前也會出現slf4j的相關錯誤,你要確保user library下的jar包應該完整。
為方便大家不走彎路,在這裡給大家貼出來需要的jar包:
大家可以根據上述jar包參考來加入。