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

舟风 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>
...全文
448 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
  • 打赏
  • 举报
回复
好洋气, 我参与的项目每一个涉及分布式的!
内容概要:本文介绍了一种基于多目标粒子群算法(MOPSO)的微电网优化调度模型,综合考虑风能、光伏、储能系统、柴油发电机、燃气轮机以及与主电网之间的能量交互等多种分布式能源的协同运行。通过构建以运行成本最小化、碳排放最低化和系统可靠性最优化为目标的多目标优化模型,利用Matlab平台实现MOPSO算法求解,完成对微电网在不同运行场景下的能量管理与调度方案优化。该模型能够有效平衡经济性与环保性之间的关系,适用于含多类型分布式电源的复杂微电网系统,具有较强的工程应用价值和科研参考意义; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及工程技术人员,尤其适合从事微电网、智能电网、综合能源系统、可再生能源集成与优化调度等领域研究的专业人士; 使用场景及目标:①用于多能源耦合微电网系统的协同优化调度研究;②支持多目标智能优化算法在能源系统中的建模与求解实践,帮助用户掌握MOPSO在实际工程问题中的应用方法;③为学术论文复现、毕业设计、科研项目开发提供完整的代码实例与技术支撑; 阅读建议:建议读者结合Matlab代码与理论文档,深入理解目标函数构建、约束条件处理及Pareto最优解集生成机制,重点关注算法参数设置、多目标权衡分析与结果可视化,并可通过调整能源配置或引入新约束进行二次开发与创新研究。

67,535

社区成员

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

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