spring JTA多数据源事务管理详细教程

<context:annotation-config />

<context:component-scan
    base-package="com.rongli.service,com.rongli.dao,com.rongli.controller" />

<tx:annotation-driven transaction-manager="springJTATransactionManager"
    proxy-target-class="true" />

<import resource="ws.cxf.xml" />


<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jta.jdbc.propertiesvalue>
        list>
    property>
bean>


<bean id="abstractXADataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    init-method="init" destroy-method="close" abstract="true">
    <property name="xaDataSourceClassName"
        value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
    <property name="poolSize" value="10" />
    <property name="minPoolSize" value="10" />
    <property name="maxPoolSize" value="30" />
    
    <property name="borrowConnectionTimeout" value="60" />
    
    <property name="reapTimeout" value="20000" />
    
    <property name="maxIdleTime" value="60" />
    
    <property name="maintenanceInterval" value="60" />
    
    <property name="loginTimeout" value="60" />
    <property name="testQuery">
        <value>select 1value>
    property>
bean>


<bean id="rlc_cus" parent="abstractXADataSource">
    <property name="uniqueResourceName" value="mysql/rlc_cus" />
    <property name="xaProperties">
        <props>
            <prop key="URL">${jdbc.rlc_cus.properties}prop>
            <prop key="user">${jdbc.rlc.user}prop>
            <prop key="password">${jdbc.rlc.password}prop>
            <prop key="pinGlobalTxToPhysicalConnection">trueprop>
        props>
    property>
bean>


<bean id="rlc_sys" parent="abstractXADataSource">
    <property name="uniqueResourceName" value="mysql/rlc_sys" />
    <property name="xaProperties">
        <props>
            <prop key="URL">${jdbc.rlc_sys.properties}prop>
            <prop key="user">${jdbc.rlc.user}prop>
            <prop key="password">${jdbc.rlc.password}prop>
            <prop key="pinGlobalTxToPhysicalConnection">trueprop>
        props>
    property>
bean>


<bean id="baseSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
    abstract="true">
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}prop>
            <prop key="hibernate.show_sql">${hibernate.format_sql}prop>
            <prop key="hibernate.format_sql">${hibernate.show_sql}prop>
            <prop key="javax.persistence.validation.mode">noneprop>
        props>
    property>
    
    <property name="packagesToScan" value="com.rongli.bean">property>
bean>



<bean id="cusSessionFactory" parent="baseSessionFactory">
    <property name="dataSource" ref="rlc_cus" />
bean>

<bean id="sysSessionFactory" parent="baseSessionFactory">
    <property name="dataSource" ref="rlc_sys" />
bean>


<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close">
    
    <property name="forceShutdown">
        <value>truevalue>
    property>
bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <property name="transactionTimeout">
        <value>2000value>
    property>
bean>


<bean id="springJTATransactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager">
        <ref bean="atomikosTransactionManager" />
    property>
    <property name="userTransaction">
        <ref bean="atomikosUserTransaction" />
    property>
bean>


<bean id="systemServiceImpl" class="com.rongli.service.impl.SystemServiceImpl">
bean>

 

转载于:https://www.cnblogs.com/walk-the-Line/p/5620841.html

你可能感兴趣的:(spring JTA多数据源事务管理详细教程)