【发布时间】:2014-11-28 08:44:07
【问题描述】:
我正在一个使用 Spring、Spring Data JPA、Spring Security、Primefaces 的项目中工作......
我正在关注 this tutorial 使用 spring 进行动态数据源路由。
在本教程中,您只能在预定义的数据源之间实现动态数据源切换。
这是我的代码的 sn-p :
springContext-jpa.xml
<bean id="dsCgWeb1" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName.Cargest_web}"></property>
<property name="url" value="${jdbc.url.Cargest_web}"></property>
<property name="username" value="${jdbc.username.Cargest_web}"></property>
<property name="password" value="${jdbc.password.Cargest_web}"></property>
</bean>
<bean id="dsCgWeb2" class="org.apache.commons.dbcp.BasicDataSource">
// same properties, different values ..
</bean>
<!-- Generic Datasource [Default : dsCargestWeb1] -->
<bean id="dsCgWeb" class="com.cargest.custom.CargestRoutingDataSource">
<property name="targetDataSources">
<map>
<entry key="1" value-ref="dsCgWeb1" />
<entry key="2" value-ref="dsCgWeb2" />
</map>
</property>
<property name="defaultTargetDataSource" ref="dsCgWeb1" />
</bean>
我想要做的是使 targetDataSources 地图也与其元素动态相同。
换句话说,我想获取某个数据库表,使用存储在该表中的属性来创建我的数据源,然后将它们放在像 targetDataSources 这样的地图中。
有没有办法做到这一点?
【问题讨论】:
标签: spring jpa spring-security spring-data-jpa