Failed to load class "org.slf4j.impl.StaticLogger

我的工程中用到hibernate3.3但运行时报如下错误

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
	at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
	at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
	at org.easyshop.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:14)
	at org.easyshop.dao.daoimp.CategoryDAOImpl.getTopCategoryList(CategoryDAOImpl.java:18)
	at org.easyshop.service.impl.ProductServiceImp.getTopCategoryList(ProductServiceImp.java:22)
	at org.easyshop.domain.test.main(test.java:13)

 很明显,少了slf4j相关的包。于是下载相关的slf4j包,我这里是slf4j1.5.5,(由于工程中用到log4j)因此选择解压后的

slf4j-log4j12-1.5.5.jar放工程的lib下,再运行报如下错:

SLF4J: This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version
Exception in thread "main" java.lang.NoSuchFieldError: name
	at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:75)
	at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:75)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
	at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
	at org.easyshop.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:14)
	at org.easyshop.dao.daoimp.CategoryDAOImpl.getTopCategoryList(CategoryDAOImpl.java:18)
	at org.easyshop.service.impl.ProductServiceImp.getTopCategoryList(ProductServiceImp.java:22)
	at org.easyshop.domain.test.main(test.java:13)

 提示工程中用到的log4j版本太低,于是下载log4j-1.2.15.jar放lib下,再运行如下错误

Exception in thread "main" java.lang.NoSuchFieldError: name
	at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:75)
	at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:75)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
	at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
	at org.easyshop.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:14)
	at org.easyshop.dao.daoimp.CategoryDAOImpl.getTopCategoryList(CategoryDAOImpl.java:18)
	at org.easyshop.service.impl.ProductServiceImp.getTopCategoryList(ProductServiceImp.java:22)
	at org.easyshop.domain.test.main(test.java:13)

 提示,相关类缺少字段name,于是到slf4j-log4j12-1.5.5里寻到Log4jLoggerAdapter类,确实看似少定义了name属性。但这样想就在错特错了,事实上是hibernate3.3里自带了slf4j-api-1.4.2.jar这个包,它和slf4j-log4j12-1.5.5版本不同,因此我在此纠结了N久~~最后将其删除,把slf4j-api-1.5.5.jar引入lib目录中,成功运行

你可能感兴趣的:(java,DAO,thread,Hibernate,log4j)