当前位置: 代码迷 >> Eclipse >> org.hibernate.HibernateException: /hibernate.cfg.xml not found
  详细解决方案

org.hibernate.HibernateException: /hibernate.cfg.xml not found

热度:143   发布时间:2016-04-23 15:07:38.0
测试类运行出现如下警告!请问怎么解决?
测试类源码:
package   ch03.hibernate;

import   org.hibernate.*;
import   org.hibernate.cfg.*;

public   class   Test   {
public   static   void   main(String[]   args)   {
try   {
SessionFactory   sf   =   new   Configuration().configure().buildSessionFactory();
Session   session   =   sf.openSession();
Transaction   tx   =   session.beginTransaction();
UserName   user   =   new   UserName();
user.setUsername( "Hibernate ");
user.setPassword( "Fra22 ");
session.save(user);
session.save(user);
tx.commit();
session.close();
}   catch   (HibernateException   e)   {
e.printStackTrace();
}
}
}

出现的警告信息!

log4j:WARN   No   appenders   could   be   found   for   logger   (org.hibernate.cfg.Environment).
log4j:WARN   Please   initialize   the   log4j   system   properly.
org.hibernate.HibernateException:   /hibernate.cfg.xml   not   found
at   org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at   org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at   org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at   org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at   ch03.hibernate.Test.main(Test.java:20)

麻烦各位看下,是什么原因!



------解决方案--------------------
log4j:WARN Please initialize the log4j system properly.
org.hibernate.HibernateException: /hibernate.cfg.xml not found
根据提示信息,没找到配置文件,可能是路径没设置正确吧。
------解决方案--------------------
你的log4j.properties没有配置。
它应该放在WEB-INF目录里面。修改里面的配置信息

classpath下log4j.xml配置错误
log4j.property和log4j.xml配置一下
  相关解决方案