繁体   English   中英

当Spring配置时,Hibernate试图查找hibernate.cfg.xml

[英]Hibernate trying to find hibernate.cfg.xml when configured by spring

我已经通过spring(4.3.5)配置了Hibernate(5.2.6),但是当我运行Junit(4.12)测试时,它发出一个错误,指出无法找到hibernate.cfg.xml文件。 谁能帮我吗?

运行Junit测试后,在数据库中创建了表,但未添加数据,我可以看到正在运行的sql查询,因为启用了show_sql

在此处输入图片说明

在web.xml中指定了休眠配置的xml文件名吗? 如果未在web.xml中指定xml文件的名称

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:hibernateContext.xml</param-value>
</context-param>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM