簡體   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