簡體   English   中英

使用Springs .hbm.xml filenotfoundException休眠

[英]Hibernate with Springs .hbm.xml filenotfoundException

我正在使用netbeans IDE,正在將休眠與spring集成。 運行程序時出現以下異常:

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [Employee.hbm.xml] cannot be opened because it does not exist

這是我的applicationContext xml文件:

 <?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/context/spring-context.xsd">


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">      
        <property name="driverClassName"  value="org.apache.derby.jdbc.ClientDriver"></property>  
        <property name="url" value="jdbc:derby://localhost:1527/sample"></property>  
        <property name="username" value="app"></property>  
        <property name="password" value="app"></property>      
    </bean>



    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>  

        <property name="mappingResources">
            <list>
                <value>Employee.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">  
            <props>  
                <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>  
                <prop key="hibernate.hbm2ddl.auto">update</prop>  
                <prop key="hibernate.show_sql">true</prop>  

            </props>  
        </property>  

    </bean>

    <bean id="template" class="org.springframework.orm.hibernate4.HibernateTemplate">  
        <property name="sessionFactory" ref="sessionFactory"></property>  
    </bean>  



    <bean class="com.office.businessLayer.Security" id="security">
    </bean>


    <bean id="dao" class="com.office.dao.EmployeeDao">
        <property name="template" ref="template"/>
    </bean>

</beans>

我已經嘗試了Internet上所有可能的解決方案,但仍然存在例外。 有人可以幫忙嗎?

這是項目目錄:

目錄

如果您的employee.hbm.xml位於應用程序的根目錄,則您的映射資源應該是這樣的。

<property name="mappingResources">
    <list>
        <value>classpath:Employee.hbm.xml</value>
    </list>
</property>

Employee.hbm.xml文件放入Employee.java所在的同一包中,並保持您的mappingResources配置不變( <value>Employee.hbm.xml</value> )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM