我尝试了多种方法来解决此错误(使用Maven项目)
<?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
如果您对此有解决方案,请告诉我
提前致谢....
找不到cfg.xml资源[/src/main/java/hibernate.cfg.xml]错误
这意味着Hibernate尝试hibernate.cfg.xml
在
/src/main/java/hibernate.cfg.xml
。
这是不正确的路径。
你应该:
hibernate.cfg.xml
中resources
的文件夹。Configuration configuration = new Configuration().configure()
的配置。hibernate.cfg.xml
位于build
文件夹的根目录中。一些解释:
Configuration configuration = new Configuration().configure()
与...相同
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
此行告诉Hibernate定位hibernate.cfg.xml
在类路径的根目录中。例如,如果您构建jar
此文件,则该文件应位于的根目录中jar
。
对于war
类路径的根是WEB-INF/classes
。
当您将文件放入文件resources
夹时,Maven会将文件夹的所有内容放入resources
类路径的根目录(jar
或的根目录)。因此,您不会在中包含该resources
文件夹,而jar
只是其中的内容。
刷新项目时,IDE也会执行相同的操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句