如何配置Spring从jar加载hibernate映射? [英] How to config Spring to load hibernate mapping from jar?
问题描述
我无法使用spring来正确加载它(我没有想把我的jar版本也放在映射中)。这是我的配置:
< bean id =sessionFactoryclass =org.springframework.orm.hibernate3.LocalSessionFactoryBean >
< property name =dataSource>< ref local =DS/>< / property>
< property name =hibernateProperties>
< ref bean =hibernateProperties/>
< / property>
< property name =mappingJarLocationsvalue =classpath *:abc - *。jar>< / property>
< / bean>
加载时没有错误,但设置资源是一个空数组。你可以帮我弄清楚这是错的吗?
谢谢,
<看起来你可能想用 mappingLocations
( JavaDoc )属性,而不是 mappingJarLocations
。在这种情况下,您只需指定 classpath:user.hbm.xml
:
< bean id =sessionFactoryclass =org.springframework.orm.hibernate3.LocalSessionFactoryBean>
< property name =dataSource>< ref local =DS/>< / property>
< property name =hibernateProperties>
< ref bean =hibernateProperties/>
< / property>
< property name =mappingLocationsvalue =classpath:/user.hbm.xml/>
< / bean>
My hibernate mapping is in a jar file for example: abc-1.0.1.jar. And the mapping files are: abc-1.0.1.jar/user.hbm.xml.
I can't get spring to load it correctly (I don't want to put my jar version in the mapping also). This is my configuration:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="DS"/></property>
<property name="hibernateProperties">
<ref bean="hibernateProperties" />
</property>
<property name="mappingJarLocations" value="classpath*:abc-*.jar"></property>
</bean>
There is no error at loading but the setting resource is an empty array. Can you help me figure out that is wrong?
Thanks,
It seems you might want to use mappingLocations
(JavaDoc) property, instead of mappingJarLocations
. In that case, you would just specify classpath:user.hbm.xml
:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="DS"/></property>
<property name="hibernateProperties">
<ref bean="hibernateProperties" />
</property>
<property name="mappingLocations" value="classpath:/user.hbm.xml"/>
</bean>
这篇关于如何配置Spring从jar加载hibernate映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!