我撘的框架 是Spring SpringMVC MyBatis
服务器用的是weblogic
现在有要求要使用weblogic配置的数据源,并且有多个数据库。
要实现分布式事务管理怎么配置?就是同一个Servece用到两个库的操作,只要有一个报错了,一起回滚的效果。
私信给你了,不知道口头描述你懂不懂
<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--引入配置属性文件 -->
<!-- 自动扫描 -->
<context:component-scan base-package="service,**.service,dao.cbk,dap.ydk,**.dao.cbk,**.dao.ydk" />
<!-- 这里是 weblogic的数据源 不知道怎么弄到 下面的配置里
<bean id="SskDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<description>实时库数据库</description>
<property name="jndiName" value="NBYB-DS-SSK"/>
</bean>
<bean id="CbkDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<description>参保库数据库</description>
<property name="jndiName" value="NBYB-DS-CBK"/>
</bean>
-->
<!-- 配置连接odao_mobile库的数据源 -->
<bean id="dataSource_YDK" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">
<!-- value只要两个数据源不同就行,随便取名 -->
<property name="uniqueResourceName" value="dataSource_YDK" />
<property name="driverClassName">
<value>${dataSource_YDK.jdbc.driver}</value>
</property>
<property name="url">
<value>${dataSource_YDK.jdbc.url}</value>
</property>
<property name="user">
<value>${dataSource_YDK.jdbc.username}</value>
</property>
<property name="password">
<value>${dataSource_YDK.jdbc.password}</value>
</property>
<property name="poolSize">
<value>1</value>
</property>
<property name="maxPoolSize">
<value>30</value>
</property>
<property name="borrowConnectionTimeout">
<value>60</value>
</property>
</bean>
<!-- 配置连接库的数据源 JTA 分布式 处理 -->
<bean id="dataSource_CBK" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">
<!-- value只要两个数据源不同就行,随便取名 -->
<property name="uniqueResourceName" value="dataSource_CBK" />
<property name="driverClassName">
<value>${dataSource_CBK.jdbc.driver}</value>
</property>
<property name="url">
<value>${dataSource_CBK.jdbc.url}</value>
</property>
<property name="user">
<value>${dataSource_CBK.jdbc.username}</value>
</property>
<property name="password">
<value>${dataSource_CBK.jdbc.password}</value>
</property>
<property name="poolSize">
<value>1</value>
</property>
<property name="maxPoolSize">
<value>30</value>
</property>
<property name="borrowConnectionTimeout">
<value>60</value>
</property>
</bean>
<bean id="webSiteSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_YDK" />
<property name="mapperLocations" value="classpath:dao/ydk/impl/*Mapper.xml,**/dao/ydk/impl/*Mapper.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="dao.ydk,**.dao.ydk" />
<property name="sqlSessionFactoryBeanName" value="webSiteSqlSessionFactory" />
</bean>
<bean id="adminSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_CBK" />
<property name="mapperLocations" value="classpath:dao/cbk/impl/*Mapper.xml,**/dao/cbk/impl/*Mapper.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="dao.cbk,**.dao.cbk" />
<property name="sqlSessionFactoryBeanName" value="adminSqlSessionFactory" />
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown">
<value>true</value>
</property>
</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 bean="atomikosTransactionManager" />
</property>
<property name="userTransaction">
<ref bean="atomikosUserTransaction" />
</property>
<!--
必须设置,否则程序出现异常 JtaTransactionManager does not support custom isolation
levels by default
-->
<property name="allowCustomIsolationLevels" value="true" />
</bean>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* service.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" read-only="true" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="save*" propagation="REQUIRED" read-only="true" />
<tx:method name="delete*" propagation="REQUIRED" read-only="true" />
<tx:method name="del*" propagation="REQUIRED" read-only="true" />
<tx:method name="update*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
上面是我配置的代码,我现在不清楚怎么配置
实时库数据库
参保库数据库
到下面的com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean里
或者 换种配置方式?
分页式事务管理可以使用JTA进行处理,具体的你网上找一下教程吧