如何配置Spring从jar加载hibernate映射? [英] How to config Spring to load hibernate mapping from jar?

查看:104
本文介绍了如何配置Spring从jar加载hibernate映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的hibernate映射是在一个jar文件中,例如:abc-1.0.1.jar。映射文件是:abc-1.0.1.jar / user.hbm.xml。



我无法使用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屋!

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