[英]Hibernate trying to find hibernate.cfg.xml when configured by spring
I have configured Hibernate(5.2.6) via spring(4.3.5) But when I run my Junit(4.12) tests it gives out an error saying that it could not locate hibernate.cfg.xml file. 我已经通过spring(4.3.5)配置了Hibernate(5.2.6),但是当我运行Junit(4.12)测试时,它发出一个错误,指出无法找到hibernate.cfg.xml文件。 Can anyone help me out? 谁能帮我吗?
After I run the Junit test, tables are created in database but data is not added, I can see the sql queries being run as I have enables show_sql 运行Junit测试后,在数据库中创建了表,但未添加数据,我可以看到正在运行的sql查询,因为启用了show_sql
did you specify hibernate configured xml file name in web.xml.? 在web.xml中指定了休眠配置的xml文件名吗? if not specify name of xml file in web.xml 如果未在web.xml中指定xml文件的名称
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:hibernateContext.xml</param-value>
</context-param>
How is applicationContext is configured for spring and hibernate integration? Spring和Hibernate集成如何配置applicationContext?
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:properties/jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>classpath:hibernate/hibernate.cfg.xml</value>
</property>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.