Maven项目集成Hibernate:hibernate.properties未找到及配置文件定位失败求助
Maven集成Hibernate时提示“hibernate.properties not found”且无法定位cfg.xml资源
我在Maven项目中集成Hibernate时碰到了个头疼的问题,尝试了好几种配置文件放置位置都没能解决:
- 把
hibernate.cfg.xml放在src根目录下,依然提示“hibernate.properties does not found”; - 移到resource目录下,错误还是一样;
- 放到webapp/WEB-INF目录下,问题依旧存在;
我的hibernate.cfg.xml配置内容如下:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testdb</property> <property name="hibernate.connection.username">postgres</property> <property name="hibernate.connection.password">sql123</property> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="hbm2ddl.auto">create </property> <property name="show_sql">true</property> <property name="format_sql">true</property> <mapping resource="Employee-hbn.xml" /> </session-factory> </hibernate-configuration>
遇到的异常信息如下:
May 22, 2018 2:28:38 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.3.0.Final} May 22, 2018 2:28:38 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Could not locate cfg.xml resource [/src/main/java/hibernate.cfg.xml] error
恳请各位提供解决方案,谢谢!
内容的提问来源于stack exchange,提问作者Jyoti Jadhav
相关产品推荐
相关产品推荐

