spring - 从classpath资源加载* .hbm.xml [英] spring - hibernate load *.hbm.xml from classpath resource
问题描述
我在位于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屋!