首页 > 其他分享 >JBPM5多数据源管理Bitronix和Atomikos

JBPM5多数据源管理Bitronix和Atomikos

时间:2023-06-04 15:04:13浏览次数:45  
标签:Atomikos jdbc http url 数据源 -- JBPM5 org color



选择哪种transaction manager?
在单数据源情况下,JDBC,Hibernate,ibatis等自带的 transaction manager已能用于处理事务。

但当设计多种数据源的事务处理时,上面的transaction manager就没法用了。这个时候可选事务管理组件有:Bitronix[url]http://docs.codehaus.org/display/BTM[/url],SimpleJTA[url]http://simplejta.sourceforge.net/[/url],Tyrex (dead?)[url]http://jotm.objectweb.org/[/url], JOTM (used in Jonas)[url]http://jencks.codehaus.org/Transaction+Manager[/url],GeronimoTM/Jencks (used in Geronimo)[url]http://jencks.codehaus.org/Transaction+Manager[/url],JBossTS (used in JBoss)[url]http://www.jboss.org/jbosstm/[/url] and Atomikos[url]http://www.atomikos.com/[/url]. [color=red][b]其中Atomikos 被大多数人所推荐[/b][/color]。

参考:[url]http://stackoverflow.com/questions/2978207/atomikos-vs-jotm-vs-bitronix-vs[/url]


一个使用[color=red][b]Bitronix[/b][/color]的applicationContext.xml

<?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:context="http://www.springframework.org/schema/context"
       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-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
       default-autowire="byName" default-lazy-init="true">


    <context:annotation-config/>

    <context:component-scan base-package="org.jbpm.dao">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    </context:component-scan>

    <context:component-scan base-package="org.jbpm.service">
        <context:include-filter type="annotation"
                                expression="org.springframework.stereotype.Service"/>
    </context:component-scan>

    <!-- =================================================================== -->
    <!-- AOP: Configuration and Aspects                                      -->
    <!-- =================================================================== -->
    <aop:config>
        <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))" order="0"/>
    </aop:config>

    <tx:advice id="txAdvice">
        <tx:attributes>
            <!-- Read-only commented out to make things easier for end-users -->
            <!-- http://issues.appfuse.org/browse/APF-556 -->
            <!--tx:method name="get*" read-only="true"/-->
            <!--<tx:method name="save*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="update*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="remove*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="get*" read-only="true"/>-->
            <!--<tx:method name="list*" read-only="true"/>-->
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>

    <!-- Enable @Transactional support -->
    <!--<tx:annotation-driven/>-->

    <!-- Enable @AspectJ support -->
    <aop:aspectj-autoproxy/>

    <!-- Enable @Configured support -->
    <!--<aop:spring-configured/>-->

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

    <bean id="basicdataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>


    <bean id="xadataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
          init-method="init" destroy-method="close">
        <property name="className" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
        <property name="uniqueName" value="jdbc/testDS1" />
        <property name="minPoolSize" value="1" />
        <property name="maxPoolSize" value="5" />
        <property name="allowLocalTransactions" value="true" />
        <property name="driverProperties">
            <props>
                <prop key="URL">${jdbc.url}</prop>
                <prop key="user">${jdbc.username}</prop>
                <prop key="password">${jdbc.password}</prop>
            </props>
        </property>
    </bean>


    <bean id="txManager"
          class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="bitronixTransactionManager" />
        <property name="userTransaction" ref="bitronixTransactionManager" />
    </bean>

    <bean id="bitronixTransactionManager" factory-method="getTransactionManager"
          class="bitronix.tm.TransactionManagerServices" depends-on="xadataSource,txManager"
          destroy-method="shutdown" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="basicdataSource"/>
        <property name="persistenceUnitName" value="leaveJPA"/>
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>

    <bean id="entityManagerFactoryJbpmPersistanceJpa" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="xadataSource" />
        <property name="persistenceUnitName" value="org.jbpm.persistence.jpa" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>

    <bean id="entityManagerFactoryJbpmTask"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="basicdataSource" />
        <property name="persistenceUnitName" value="org.jbpm.task" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />

                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryJbpmPersistanceJpa"/>
    </bean>

    <bean id="taskTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryJbpmTask"/>
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>


    <!--<bean id="md5PasswordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>-->

</beans>



一个使用[color=red][b]Atomikos[/b][/color]的applicationContext.xml


<?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:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xsi:schemaLocation="
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
				http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       			http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

    <!-- active component annotations like @Service,@Repository,@Component -->  
    <context:component-scan base-package="cmei.mysql" >
    <!--  <context:include-filter type="regex" expression=".dao.*"/>-->
    </context:component-scan>


    <aop:aspectj-autoproxy/>


    <!-- active annotations like @autowired, @required,... in java class,have to add xmlns:context to beans header-->    
   	<!-- <context:annotation-config/>  removed after using context:component-scan-->    

	<!--step1:dataSource from connection pool, must use atomikos data source -->
	 <bean id="dataSource11" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
		 <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
		 <property name="uniqueResourceName" value="mysql/test_transaction"></property>
		 <property name="poolSize" value="10"></property>
		 <property name="xaProperties">
		 	<props>
		 		<prop key="url">jdbc:mysql://localhost:3306/test_transaction</prop>
		 		<prop key="user">root</prop>
		 		<prop key="password"></prop>
		 	</props>
		 </property>
	 </bean>	


	  <bean id="dataSource22" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
		 <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
		 <property name="uniqueResourceName" value="mysql/test_transaction2"></property>
		 <property name="poolSize" value="10"></property>
		 <property name="xaProperties">
		 	<props>
		 		<prop key="url">jdbc:mysql://localhost:3306/test_transaction2</prop>
		 		<prop key="user">root</prop>
		 		<prop key="password"></prop>
		 	</props>
		 </property>
	 </bean>

	 <!-- step2:sql session:mybatis --> 
	 <bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource11" />
		<property name="mapperLocations" value="/mappers/*.xml" />
		<property name="typeAliasesPackage" value="cmei.mysql.dao" />
	 </bean>

	<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource22" />
		<property name="mapperLocations" value="/mappers/*.xml" />
		<property name="typeAliasesPackage" value="cmei.mysql.dao" />
	 </bean>

	<!-- step 3:config different daos and service-->
	<bean id="accountDAO1" class="cmei.mysql.dao.AccountDAO">
		<property name="sqlSessionFactory" ref="sqlSessionFactory1"></property>
	</bean>

	<bean id="accountDAO2" class="cmei.mysql.dao.AccountDAO">
		<property name="sqlSessionFactory" ref="sqlSessionFactory2"></property>
	</bean>
		<bean id="accountService" class="cmei.mysql.dao.AccountService">
		<property name="accountDAO1" ref="accountDAO1"></property>
		<property name="accountDAO2" ref="accountDAO2"></property>
	</bean>

	<!-- step4:config transactionManager atomikos -->
	<bean id="atomikosTransactionManager"
	      class="com.atomikos.icatch.jta.UserTransactionManager" 
	      init-method="init" destroy-method="close">
	      <property name="forceShutdown" value="true"/>
	</bean>
	<bean id="atomikoUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
		<property name="transactionTimeout" value="300"></property>
	</bean>

	<!-- step5:config spring JTA transactionManager -->
	<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="transactionManager" ref="atomikosTransactionManager"></property>
		<property name="userTransaction" ref="atomikoUserTransaction"></property>
	</bean>	 

	<!-- step6:config aop  -->
	<tx:annotation-driven transaction-manager="springTransactionManager" proxy-target-class="true"  />

	<tx:advice id="txAdvice" transaction-manager="springTransactionManager">
		<tx:attributes>
			<tx:method name="update*" rollback-for="Exception"/>
			<tx:method name="*" read-only="true" rollback-for="Exception"/>
		</tx:attributes>
	</tx:advice>

	<aop:config>
		<aop:pointcut expression="execution(* cmei.mysql.dao.AccountService.transfer(..))" id="serviceOperation"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
	</aop:config>

</beans>

标签:Atomikos,jdbc,http,url,数据源,--,JBPM5,org,color
From: https://blog.51cto.com/u_3871599/6410694

相关文章

  • JBPM5的一些概念
    [color=darkblue][b]人工任务分三部分[/b][/color]:1.运行一项[b][color=red]任务服务器[/color][/b],不仅启动了TaskServer,同时还加载了如群组,用户等数据。2.启动一个[color=red][b]流程实例[/b][/color],这个类的功能是启动一个流程实例。3.[color=red][b]......
  • JBPM5入门资料
    [color=darkblue][b]jBPM5.4-01:jbpm-5.4.0安装[/b][/color][url]http://xujava.iteye.com/blog/1839918[/url][color=red][b]jbpm5创建SimpleDemo步骤[/b][/color]:[url]http://wenku.baidu.com/view/dccf328e84868762caaed5b8.html[/url][color=red][b]J......
  • Spring配置数据源
    1.Spring配置数据源1.1数据源(连接池)的作用数据源(连接池)是提高程序性能如出现的事先实例化数据源,初始化部分连接资源使用连接资源时从数据源中获取使用完毕后将连接资源归还给数据源常见的数据源(连接池):DBCP、C3P0、BoneCP、Druid等开发步骤①导入数据源的坐标和数据......
  • 基于Grafana的WebUI添加Prometheus数据源(三)
    基于Grafana的WebUI添加Prometheus数据源(三)1、Grafana介绍1.1什么是GrafanaGrafana是一款近几年比较流行的开源数据绘图工具平台。Grafana原生支持包括但不限于InfluxDB,MySQL,OpenTSDB,PostgreSQL和Prometheus等多种数据源作为输入源数据。官方地址:https://grafana.com......
  • 阿里Druid数据源,程序启动或日志记录报错 load filter error, filter not found : logb
      Druid支持配置多种Filter,配置信息保存在druid-xxx.jar!/META-INF/druid-filter.properties下面,具体如下:druid.filters.default=com.alibaba.druid.filter.stat.StatFilterdruid.filters.stat=com.alibaba.druid.filter.stat.StatFilterdruid.filters.mergeStat=com.a......
  • OpenMLDB v0.8 新功能:离线引擎数据源支持 Amazon S3
    简介AmazonS3(以下简称S3)是一种非常受欢迎的云存储服务,它以其卓越的扩展性、安全性和稳定性而广受全球企业和开发者的喜爱。在新发布的OpenMLDBv0.8.0版本中,新增加了对于AmazonS3作为离线数据源的支持,其带来的主要好处包括:安全性和稳定性:S3提供高级别的安全保障,以保护......
  • el-cascader 切换数据源时报错
    问题根据属性类型加载el-cascader不同的数据源选项,会报错如下:尝试猜测是:el-cascader上次的绑定值没有清空,而切换属性类型导致数据源选项不同,以致于无法在新的选项中找到绑定值,从而报错。于是,设置了切换属性类型时,把el-cascader的绑定值重置为[]。但仍然存在这个报错。......
  • mybatis配置多数据源
    yml中配置mybatis的日志输出信息mybatis:#springboot集成mybatis的方式打印sqlconfiguration:log-impl:org.apache.ibatis.logging.stdout.StdOutImplmaven引入相关的配置<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>my......
  • 实例讲解Spring boot动态切换数据源
    摘要:本文模拟一下在主库查询订单信息查询不到的时候,切换数据源去历史库里面查询。本文分享自华为云社区《springboot动态切换数据源》,作者:小陈没烦恼。前言在公司的系统里,由于数据量较大,所以配置了多个数据源,它会根据用户所在的地区去查询那一个数据库,这样就产生了动态切换数据源......
  • 实例讲解Spring boot动态切换数据源
    摘要:本文模拟一下在主库查询订单信息查询不到的时候,切换数据源去历史库里面查询。本文分享自华为云社区《springboot动态切换数据源》,作者:小陈没烦恼。前言在公司的系统里,由于数据量较大,所以配置了多个数据源,它会根据用户所在的地区去查询那一个数据库,这样就产生了动态切换数......