spring - 从classpath资源加载* .hbm.xml [英] spring - hibernate load *.hbm.xml from classpath resource

查看:118
本文介绍了spring - 从classpath资源加载* .hbm.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在位于src / main / resources maven的文件夹中的classpath资源中有一些hbm.xml文件。我使用Spring的LocalSessionFactoryBean以下面的bean配置加载这些文件:

 < bean id =hibernateSessionFactoryclass =org .springframework.orm.hibernate3.LocalSessionFactoryBean> 
< property name =dataSourceref =dataSourceOracle/>
< property name =mappingResources>
< list>
<值>映射/ SystemUser.hbm.xml< /值>
<值>映射/ SystemCredential.hbm.xml< /值>
<值>映射/ SystemProvince.hbm.xml< /值>
< / list>
< / property>
< property name =hibernateProperties>
<值>
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
< / value>
< / property>
< / bean>

但它给了我FileNotFoundException。请告诉我我做了什么错误
谢谢。

解决方案

位于当使用类型为 war 的项目使用Maven时,src / main / resources 结束于 WEB-INF / classes code>(并保存 resources 目录结构)。因此,请将您的映射文件放在 src / main / resources / mapping 中或使用以下配置:

 < bean id =hibernateSessionFactoryclass =org.springframework.orm.hibernate3.LocalSessionFactoryBean> 
< property name =dataSourceref =dataSourceOracle/>
< property name =mappingResources>
< list>
<值> SystemUser.hbm.xml< /值>
<值> SystemCredential.hbm.xml< /值>
<值> SystemProvince.hbm.xml< /值>
< / list>
< / property>
< property name =hibernateProperties>
<值>
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
< / value>
< / property>
< / bean>


I have some hbm.xml files in classpath resource located in src/main/resources maven's folder. I used spring's LocalSessionFactoryBean to load these files with the following bean config:

<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSourceOracle"/>
    <property name="mappingResources">
        <list>
            <value>mapping/SystemUser.hbm.xml</value>
            <value>mapping/SystemCredential.hbm.xml</value>
            <value>mapping/SystemProvince.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <value>
            hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
        </value>
    </property>
</bean>

But it gives me the FileNotFoundException. Please tell me what i've done wrong Thank you.

解决方案

Files located in src/main/resources end up in WEB-INF/classes when using Maven with a project of type war (and the resources directory structure is preserved). So either place your mapping files in src/main/resources/mapping or use the following configuration:

<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSourceOracle"/>
        <property name="mappingResources">
                <list>
                        <value>SystemUser.hbm.xml</value>
                        <value>SystemCredential.hbm.xml</value>
                        <value>SystemProvince.hbm.xml</value>
                </list>
        </property>
        <property name="hibernateProperties">
        <value>
                hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
        </value>
    </property>
</bean>

这篇关于spring - 从classpath资源加载* .hbm.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆