一.atomikos 3.7 包与jta.properties
1.transactions-jdbc.jar
2.transactions.jar
3.transactions-jta.jar
4.transactions-api.jar
5.atomikos-util.jar
jta.properties
com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.console_file_name = tm.out
com.atomikos.icatch.log_base_name = tmlog
com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm
com.atomikos.icatch.console_log_level =INFO
二。数据库配置
<!-- oracle -->
<bean id="oracleDS" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<description>oracle xa datasource</description>
<property name="uniqueResourceName">
<value>oracle_ds</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">pms</prop>
<prop key="password">pms123</prop>
<prop key="URL">jdbc:oracle:thin:@10.243.1.224:1521:pspdb</prop>
</props>
</property>
<property name="testQuery">
<value>select 1 from dual</value> <!-- 尽力加上,不然会出现告警 -->
</property>
</bean>
<!-- mysql数据源定义 -->
<bean id="mysqlDS" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<description>mysql xa datasource</description>
<property name="uniqueResourceName">
<value>mysql_ds</value>
</property>
<property name="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">root</prop>
<prop key="password">123456</prop>
<prop key="URL">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8</prop>
</props>
</property>
<property name="testQuery">
<value>select 1</value><!--尽力加上,不然会出现告警 -->
</property>
</bean>
sqlSessionFactory
<!-- mysql mybatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="mysqlDS" />
<!-- 自动扫描entity目录,省略Configuration.xml里手工配置 -->
<!-- <property name="mapperLocations" value="classpath*:mybatis/sql/**/*.xml" /> -->
<property name="mapperLocations" value="classpath*:mybatis/sql/scadmin/ScadminTestMapper.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- <property name="basePackage" value="com.etonetech.sc.**.dao,demo.dao"/> -->
<!-- <property name="basePackage" value="com.etonetech.sc.**.dao"/> -->
<property name="basePackage" value="com.etonetech.sc.**.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
<!-- oracle mybatis文件 -->
<bean id="sqlSessionFactoryPMS" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="oracleDS" />
<!-- 自动扫描entity目录,省略Configuration.xml里手工配置 -->
<!-- <property name="mapperLocations" value="classpath*:mybatis/sql/**/*.xml" /> -->
<property name="mapperLocations" value="classpath*:mybatis/sql/scadmin/TempTesScadmintMapper.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- <property name="basePackage" value="com.etonetech.sc.**.dao,demo.dao"/> -->
<!-- <property name="basePackage" value="com.etonetech.sc.**.dao"/> -->
<property name="basePackage" value="com.etonetech.sc.**.testDao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryPMS" />
</bean>
<!--spring管理atomikos -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<description>UserTransactionManager</description>
<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="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction" />
<property name="allowCustomIsolationLevels" value="true"/>
</bean>
事务拦截器:
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="springTransactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
<property name="beanNames">
<list>
<value>*Action</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
四.测试日志