JTOM分布式事物配置

<?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"
 xsi:schemaLocation="http://www.springframework.org/schema/beans 
                     http://www.springframework.org/schema/beans/spring-beans.xsd 
                     http://www.springframework.org/schema/tx 
                     http://www.springframework.org/schema/tx/spring-tx.xsd 
                     http://www.springframework.org/schema/aop 
                     http://www.springframework.org/schema/aop/spring-aop.xsd"
 default-lazy-init="true">
 <!-- 1. JOTM本地实例 -->
 <bean id="jotm"
  class="org.springframework.transaction.jta.JotmFactoryBean" />

 <!-- 2. JTA事务管理器 -->
 <bean id="txManager"
  class="org.springframework.transaction.jta.JtaTransactionManager">
  <!-- 2.1:指定userTransaction属性 -->
  <property name="userTransaction" ref="jotm" />
 </bean>

 <!-- 3. XAPool配置,内部包含了一个XA数据源,对应user数据库 -->
 <bean id="dataDataSource"
  class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
  destroy-method="shutdown">
  <property name="dataSource">
   <!-- 3.1:内部XA数据源 -->
   <bean class="org.enhydra.jdbc.standard.StandardXADataSource"
    destroy-method="shutdown">
    <property name="transactionManager" ref="jotm" />
    <property name="driverName"
     value="oracle.jdbc.driver.OracleDriver" />
    <property name="url"
     value="jdbc:oracle:thin:@127.0.0.1:1521:cqsdb" />
   </bean>
  </property>
  <property name="user" value="data" />
  <property name="password" value="data" />
 </bean>

 <!-- 4. 配置另一个XAPool,对应address数据库 -->
 <bean id="centerDataSource"
  class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
  destroy-method="shutdown">
  <property name="dataSource">
   <bean class="org.enhydra.jdbc.standard.StandardXADataSource"
    destroy-method="shutdown">
    <property name="transactionManager" ref="jotm" />
    <property name="driverName"
     value="oracle.jdbc.driver.OracleDriver" />
    <property name="url"
     value="jdbc:oracle:thin:@127.0.0.1:1521:cqsdb" />
   </bean>
  </property>
  <property name="user" value="datacenter" />
  <property name="password" value="datacenter" />
 </bean>

 <!-- 5. 配置对应userDataSource数据源的userSessionFactory -->
 <bean id="dataSessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataDataSource" />
  </property>
  <property name="lobHandler" ref="oracleLobHandler" /><!-- for lob proc -->
  <property name="mappingDirectoryLocations">
   <list>
    <value>classpath:com/euler/orm</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.Oracle9Dialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.jdbc.batch_size">50</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.cache.provider_class">
     org.hibernate.cache.EhCacheProvider
    </prop>
   </props>
  </property>
  <!-- 5.1 这里不要配,否则会报Could not find UserTransaction in JNDI [java:comp/UserTransaction]    
   <property name="jtaTransactionManager">  
   <ref bean="jotm" />  
   </property>    
  -->
 </bean>

 <!-- 6. 配置对应addressDataSource数据源的addressSessionFactory -->
 <bean id="centerSessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="centerDataSource" />
  </property>
  <property name="lobHandler" ref="oracleLobHandler" /><!-- for lob proc -->
  <property name="mappingDirectoryLocations">
   <list>
    <value>classpath:com/euler/orm</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.Oracle9Dialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.jdbc.batch_size">50</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.cache.provider_class">
     org.hibernate.cache.EhCacheProvider
    </prop>
   </props>
  </property>
  <!-- 6.1 这里不要配,否则会报Could not find UserTransaction in JNDI [java:comp/UserTransaction]    
   <property name="jtaTransactionManager">  
   <ref bean="jotm" />  
   </property>  
  -->
 </bean>



 <!-- 7. 对应userSessionFactory数据源的userDao -->
 <bean id="BaseHibernateDAO"
  class="com.zjwy.dao.impl.BaseHibernateDAO">
  <property name="sessionFactory">
   <ref bean="centerSessionFactory"></ref>
  </property>
 </bean>
 <!-- dao实现类 -->
 <bean id="BaseHibernateDAOdata"
  class="com.zjwy.dao.impl.BaseHibernateDAOdata">
  <property name="sessionFactory">
   <ref bean="dataSessionFactory"></ref>
  </property>
 </bean>


 <bean id="ExtHibernateDAO"
  class="com.zjwy.dao.impl.ExtHibernateDAO">
  <property name="sessionFactory">
   <ref bean="centerSessionFactory"></ref>
  </property>
 </bean>


 <!-- 9. 进行跨数据库JTA事务的业务类 -->
 <bean id="AbstractService"
  class="com.euler.services.AbstractService" abstract="true">
  <property name="dao" ref="BaseHibernateDAO"></property>
  <property name="datadao" ref="BaseHibernateDAOdata"></property>
 </bean>

 <!-- 10. 事务拦截器 -->
 <bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="txManager" />
  <property name="transactionAttributes">
   <props>
    <prop key="*">-Exception</prop>
   </props>
  </property>
 </bean>

 <!-- 11. 事务增强器 -->
 <bean id="transactionAdvisor"
  class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
  <property name="transactionInterceptor"
   ref="transactionInterceptor" />
 </bean>

 <!-- 12. 自动代理 -->
 <bean id="beanproxy"
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
   <!-- <value>execution(* com.euler.services..*.*(..))</value> -->
   <list>
   <!-- 配置事物范围 -->
    <value>*SrvImpl</value>
    <value>AutoSynchronizationDatasService</value>
    <value>EulerDBSynSvrImp</value>
   </list>
  </property>
  <property name="interceptorNames">
   <list>
    <value>transactionAdvisor</value>
   </list>
  </property>
 </bean>



 <bean id="oracleLobHandler"
  class="org.springframework.jdbc.support.lob.OracleLobHandler">
  <property name="nativeJdbcExtractor">
   <ref local="nativeJdbcExtractor" />
  </property>
 </bean>
 <bean id="nativeJdbcExtractor"
  class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor">
 </bean>
 </beans>

 

Tomcat  lib 下 需要一个  javaee.jar

你可能感兴趣的:(分布式)