是否可以在spring会话工厂中配置多个数据源?
DataSource 1是
java:/comp/env/jdbc/names;
DataSource 2是
java:/comp/env/jdbc/address;
Session Factory正在为DataSource 1工作。如何包含DataSource2?
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>myApp.dao</value>
<value>myApp.domain</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</prop>
<prop key="hibernate.connection.datasource">java:/comp/env/jdbc/names</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
感谢。您的信息非常有用。我走了这条路。
解决方案 Hibernate configuring multiple datasources and multiple session factories
答案 0 :(得分:1)
您可以使用Spring div {
width: 250px;
height: 100px;
line-height: 100px;
text-align: center;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
并提供实现,以便在运行时切换数据源。看看这个example
答案 1 :(得分:0)
您可以按照以下方式执行此操作
<bean id="parentDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
abstract="true">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="username" value="sa"/>
</bean>
<bean id="goldDataSource" parent="parentDataSource">
<property name="url" value="jdbc:hsqldb:hsql://localhost:${db.port.gold}/blog"/>
</bean>
<bean id="silverDataSource" parent="parentDataSource">
<property name="url" value="jdbc:hsqldb:hsql://localhost:${db.port.silver}/blog"/>
</bean>
<bean id="bronzeDataSource" parent="parentDataSource">
<property name="url" value="jdbc:hsqldb:hsql://localhost:${db.port.bronze}/blog"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/blog/datasource/db.properties"/>
</bean>