java - Hibernate JUnit 找不到 hibernate.cfg.xml

标签 java eclipse hibernate junit

使用 JUnit 构建SessionFactory 时脚本出错。我也尝试过使用:

 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();

关于java - Hibernate JUnit 找不到 hibernate.cfg.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495940/

相关文章:

java - 我将如何向弹出菜单添加单选按钮?

java - tomcat 7.0.56 windows (eclipse) 尾部附加斜杠; tomcat 7.0.28 linux(已部署的 war )未附加尾部斜杠

java - SVN 我的项目没有显示

java - 使用 hibernate 与 spring data jpa 和 mysql 组合主键

java - Spring 数据存储库将 null 作为 bytea 发送到 PostgreSQL 数据库

java - 如何编写通用方法在数组中插入元素?

java - 退出应用程序时出现闪屏 Activity

java - Spring的转换服务不调用转换器到字符串(用于显示目的)

android - 将libgdx项目导入Eclipse时出现Gradle错误

hibernate - gradle 说, 'see compiler error output' ,但没有