求助!!!玩过分布式数据库的专家,请指点数据库连接池的方法如何配置数据源

舟风 2013-12-15 08:22:26
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="com.al.persistence.testcase.bmo.impl"/>
<!-- 第一个数据库 -->
<bean id="dataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="oracle1"/>
<property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
<property name="xaProperties">
<props>
<prop key="user">sr</prop>
<prop key="password">sr</prop>
<prop key="URL">jdbc:oracle:thin:@192.168.74.15:1522:jttest</prop>
</props>
</property>
</bean>
<!-- 第二个数据库 -->
<bean id="dataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="oracle2"/>
<property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
<property name="xaProperties">
<props>
<prop key="user">crm</prop>
<prop key="password">crm</prop>
<prop key="URL">jdbc:oracle:thin:@192.168.74.15:1522:jttest</prop>
</props>
</property>
</bean>
<!-- 持久层数据库操作主类 -->
<bean class="com.al.persistence.routing.RoutingSqlSessionFactoryBean">
<property name="targetDataSources">
<map>
<entry key="ds2" value-ref="dataSource2"/>
<entry key="ds1" value-ref="dataSource1"/>
</map>
</property>
<property name="strategy" value="com.al.persistence.testcase.routing.RoutingSessionStrategy"/><!-- 分库策略实现类 -->
<property name="configLocation" value="classpath:ibatis/configuration.xml"/>
</bean>
<bean class="com.al.persistence.ExtMapperScannerConfigurer">
<property name="basePackage" value="com.al.persistence.testcase.mapper"/>
</bean>
<!-- JTA事务 -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="true"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.al.persistence.testcase.bmo.impl.*.*(..))" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="insert*"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="get*" read-only="true"/>
</tx:attributes>
</tx:advice>
</beans>


以上是我的配置,网上找了半天没有找到在Spring配置分布式数据源atomikos包中用类似JNDI的配置方式。因为以下这种方式只要通过对应的中间件服务器(WAS或者WEBLOGIC里面数据库连接池配置)就可以不用在应用层面了解对应的用户名密码,生产系统客户可能3个月改一次密码,如果要通过每次改Spring里面配置的方式修改密码,问题很大,请各位涉及过这方面的高手大师能提供分布式数据库数据库连接池方式的配置方案。万分谢谢!
参考JNDI代码如下:
	<!-- 配置JNDI -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${sr.jndiDataSource}"></property>
</bean>
...全文
391 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
舟风 2013-12-20
  • 打赏
  • 举报
回复
非常感谢各位的回帖,但是仍然没有解决我想解决的问题:“不能在应用层面配置数据库的用户名和密码”
纳兰弦歌 2013-12-18
  • 打赏
  • 举报
回复
舟风 2013-12-17
  • 打赏
  • 举报
回复
非常感谢各位关注,但是仍然没有解决我想解决的问题:“不能在应用层面配置数据库的用户名和密码”
  • 打赏
  • 举报
回复
分布式事务和数据源配置http://www.jdon.com/30264
  • 打赏
  • 举报
回复
Spring中数据源的集中配置方法:http://blog.csdn.net/liyangbing315/article/details/4730961
平菇虾饺 2013-12-16
  • 打赏
  • 举报
回复
好洋气, 我参与的项目每一个涉及分布式的!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧