【发布时间】:2020-02-05 17:23:56
【问题描述】:
这是我的休眠配置文件。我把它放在 src/main/resources 中,我把它放在 src 中。
但我总是收到此错误:
找不到 cfg.xml 资源 [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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
</session-factory>
</hibernate-configuration>
这就是我编写配置文件的方式。我正在使用弹簧。我刚刚发现,实际上所有这些在春天都是不必要的。你可以自动装配 SessionFactory。
【问题讨论】:
-
文件是否名为
hibernate.cfg.xml? -
是 hibernate.cfg.xml
-
是spring boot项目吗?以及哪个 Spring 和 Hibernate 版本?
-
我正在使用 Spring Framework 4.3.3 和 Hibernate 5 。该项目是几年前建立的。