说:
在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>
在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>
本文深入探讨了在Spring框架中使用Hibernate作为持久层时,如何正确配置`hibernate.cfg.xml`文件,并解决了配置多个配置文件时遇到的逗号分割问题。通过解析Spring和Hibernate的源码,揭示了配置文件处理机制,最终提供了有效的配置解决方案。
2589

被折叠的 条评论
为什么被折叠?



