关于activiti-5.22.0.0不支持事务解决方法

Posted smallice

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于activiti-5.22.0.0不支持事务解决方法相关的知识,希望对你有一定的参考价值。

去年在做OA的时候使用activiti-5.22.0.0做为bpm的管理引擎,不过集成进来时候,在项目即将上线的时候发现activiti这个版本不支持事务。

所以在这里给出解决方案,希望给遇到小伙伴提供一种解决方法

<?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:aop="http://www.springframework.org/schema/aop"
       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-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    <tx:advice id="activitiTxAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="notify*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="delegate*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="complete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="resolve*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="claim*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="unclaim*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="new*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="suspend*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="activate*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="start*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="signal*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="submit*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="execute*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:advisor pointcut="execution(* org.activiti.engine.*Service.*(..))" advice-ref="activitiTxAdvice"/>
        <aop:advisor pointcut="execution(* com.cfne.cuckoo..service..*Service.*(..))" advice-ref="activitiTxAdvice"/>
    </aop:config>
    
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="databaseSchemaUpdate" value="true"/>
        <property name="jobExecutorActivate" value="false"/>
        <!-- Async executor通过线程池的方式管理线程。activiti默认激活使用job executor,
            要使用async executor替代job executor需在配置文件中定义一下两个属性 -->
        <property name="asyncExecutorActivate" value="true"/>
        <property name="asyncExecutorEnabled" value="true"/>
        <property name="historyLevel" value="FULL"/>
        <property name="activityFontName" value="宋体"/>
        <property name="labelFontName" value="宋体"/>
        <!--<property name="mailServerHost" value="smtp.qq.com"/>
        <property name="mailServerPort" value="465"/>
        <property name="mailServerDefaultFrom" value="[email protected]"/>
        <property name="mailServerUsername" value="[email protected]"/>
        <property name="mailServerPassword" value="*******"/>
        <property name="mailServerUseSSL" value="true"/>
        <property name="formTypes">
            <list>
                <bean class="org.activiti.explorer.form.UserFormType"/>
                <bean class="org.activiti.explorer.form.ProcessDefinitionFormType"/>
                <bean class="org.activiti.explorer.form.MonthFormType"/>
            </list>
        </property>-->
    </bean>

    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
    </bean>

    <!-- 初始化需要使用的Service -->
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
    <bean id="formService" factory-bean="processEngine" factory-method="getFormService"/>
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>

</beans>

我在这里使用spring XML的配置方法来解决方法

以上是关于关于activiti-5.22.0.0不支持事务解决方法的主要内容,如果未能解决你的问题,请参考以下文章

关于分布式事务

FoundationDB :一个支持分布式事务架构解藕的 k/v存储系统

关于事务的学习

面试突击86:SpringBoot 事务不回滚?怎么解决?

MySql关于缺省值时事务的处理(转)

大数据开发:关于MYSQL存储引擎详解