繁体   English   中英

Hibernate JUnit找不到hibernate.cfg.xml

[英]Hibernate JUnit can't find hibernate.cfg.xml

使用JUnit进行buildSessionFactory时,脚本给出错误。 我也尝试使用:

 return new Configuration().configure("src/test/resources/META-INF/hibernate.cfg.xml").buildSessionFactory();

我一直在移动它,但是每次运行它时。 该测试方法找不到hibernate.cfg.xml。

特别是我也在使用Maven2。

错误:

SessionFactory creation failed.org.hibernate.HibernateException: src/test/resources/META-INF/hibernate.cfg.xml not found

我的项目/工作区名称也为“ test”,所以我也尝试了“ test / src / test”。 没用

删除“ src”,然后重试运行。

return new Configuration().configure("/test/resources/META-INF/hibernate.cfg.xml").buildSessionFactory();

正确的形式是:

return new Configuration().configure("/META-INF/hibernate.cfg.xml").buildSessionFactory();

configure(String)方法将查找类路径资源,并且在运行测试时, /src/test/resources/下的所有内容都可以在Maven的类路径上找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM