Spring+jta+Hibernate的跨库处理的配置

系统 1839 0

配置文件如下: ( 对应的表的引擎要是 INNODB 的才可以 )

<? 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-2.0.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >

   

    <!-- 数据源 1 -->

    < bean id = "dataSource1" class = "com.atomikos.jdbc.SimpleDataSourceBean" init-method = "init" destroy-method = "close" >

    < property name = "uniqueResourceName" >   

            < value > mysql/main </ value >   

        </ property >   

        < property name = "xaDataSourceClassName" >   

            <!-- 使用 Mysql XADataSource(mysql>=5.0, Connector/J>=5.0 才可以支持 XADatasource)-->   

            < value > com.mysql.jdbc.jdbc2.optional.MysqlXADataSource </ value >

        </ property >   

        < property name = "xaDataSourceProperties" >   

            < value > URL=jdbc:mysql://localhost:3306/test?useUnicode=true &amp; characterEncoding=utf-8;user=root;password=123456 </ value >   

        </ property >  

         < property name = "validatingQuery" >

            < value > SELECT 1 </ value >   

        </ property >

    </ bean >

    <!-- 数据源 2 -->

    < bean id = "dataSource2" class = "com.atomikos.jdbc.SimpleDataSourceBean" init-method = "init" destroy-method = "close" >   

        < property name = "uniqueResourceName" >   

            < value > mysql/secondary </ value >   

        </ property >   

        < property name = "xaDataSourceClassName" >   

            <!-- 使用 Mysql XADataSource(mysql>=5.0, Connector/J>=5.0 才可以支持 XADatasource)-->   

            < value > com.mysql.jdbc.jdbc2.optional.MysqlXADataSource </ value >   

        </ property >

        < property name = "xaDataSourceProperties" >   

            < value > URL=jdbc:mysql://localhost:3306/test2?useUnicode=true &amp; characterEncoding=utf-8;user=root;password=123456 </ value >   

        </ property >

         < property name = "validatingQuery" >

            < value > SELECT 1 </ value >   

        </ property >

    </ bean >

   

    < 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 >

   

    <!-- JTA 事务管理器 -->

    < bean id = "springTransactionManager" class = "org.springframework.transaction.jta.JtaTransactionManager" >

       < property name = "transactionManager" ref = "atomikosTransactionManager" />

       < property name = "userTransaction" ref = "atomikosUserTransaction" />

    </ bean >

   

    <!-- 第一个 sessionFactory ,有多少个数据库就要有多少个数据源,也就要有多少个 sessionFactory ,每个 sessionFactory 对应一个数据源 -->

    < bean id = "sessionFactory1" class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >

       < property name = "dataSource" ref = "dataSource1" />

       < property name = "annotatedClasses" >

           < list >

              < value > org.zsl.jta.model.User </ value >

           </ list >

       </ property >

       < property name = "hibernateProperties" >

           < props >

              < prop key = "hibernate.dialect" > org.hibernate.dialect.MySQLDialect </ prop >

              < prop key = "hibernate.show_sql" > true </ prop >

              < prop key = "hibernate.hbm2ddl.auto" > update </ prop >

              <!--

              <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>

              <prop key="hibernate.cache.use_query_cache">true</prop>

                -->

           </ props >

       </ property >

    </ bean >   

分享到:
评论

Spring+jta+Hibernate的跨库处理的配置


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论