在spring配置多个hibernate.cfg.xml

说:
在Hibernate-content.xml中
说:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocations"
value="classpath:hibernate.cfg.xml" />

说:
classpath:hibernate.cfg.xml
说:
如果我有新的 hibernate.cfg.xml 如果加入到这里来
说:
我试了用逗号分割,不可以的
说:
我的配置是classpath:hibernate.cfg.xml,classpath:xxxx.cfg.xml
today 说:
我估计这样不行,在hibernater的源码是这样处理的:
today 说:
public Configuration configure() throws HibernateException {
configure( "/hibernate.cfg.xml" );
return this;
}
today 说:
public Configuration configure(String resource) throws HibernateException {
log.info( "configuring from resource: " + resource );
InputStream stream = getConfigurationInputStream( resource );
return doConfigure( stream, resource );
}
today 说:
也就是说他会对String resource进行分折,然后做循环。
today 说:
又查了一个spring的源码。这样做是可以的。在spring当中它做了一次循环。
today 说:
它的方式是:"classpath:hibernate.cfg.xml,classpath:extension.cfg.xml"
<property name="configLocations">
<list>
<value>classpath:hibernate_admin.cfg.xml</value>
<value>classpath:hibernate_admin.cfg.xml</value>
</list>
</property>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值