關於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="352004760@qq.com"/>
        <property name="mailServerUsername" value="352004760@qq.com"/>
        <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的配置方法來解決方法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM