Spring整合Activiti

步骤一:导入依赖

                <!--activiti常规依赖-->
                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-engine</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-bpmn-model</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-bpmn-converter</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-json-converter</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-bpmn-layout</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <dependency>
                  <groupId>org.activiti.cloud</groupId>
                  <artifactId>activiti-cloud-services-api</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <!--activiti和Spring整合依赖-->
                <dependency>
                  <groupId>org.activiti</groupId>
                  <artifactId>activiti-spring</artifactId>
                  <version>7.0.0.Beta1</version>
                </dependency>

                <!--数据库依赖-->
                <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <version>5.1.38</version>
                </dependency>


                <!--单测依赖-->
                <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.12</version>
                </dependency>

                <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-test</artifactId>
                  <version>5.0.7.RELEASE</version>
                </dependency>


                <!-- log start -->
                <dependency>
                  <groupId>log4j</groupId>
                  <artifactId>log4j</artifactId>
                  <version>${log4j.version}</version>
                </dependency>
                <dependency>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-api</artifactId>
                  <version>${slf4j.version}</version>
                </dependency>
                <dependency>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-log4j12</artifactId>
                  <version>${slf4j.version}</version>
                </dependency>


                <dependency>
                  <groupId>org.mybatis</groupId>
                  <artifactId>mybatis</artifactId>
                  <version>3.4.5</version>
                </dependency>


                <!--数据源-->
                <dependency>
                  <groupId>commons-dbcp</groupId>
                  <artifactId>commons-dbcp</artifactId>
                  <version>1.4</version>
                </dependency>

                <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
                <dependency>
                  <groupId>commons-io</groupId>
                  <artifactId>commons-io</artifactId>
                  <version>2.4</version>
                </dependency>
            

步骤二:配置Activiti

  配置内容:1.数据源         2.配置processEngine对象        3.配置XXXXService

<?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:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/contex
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!--数据源-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/activiti"/>
        <property name="username" value="root"/>
        <property name="password" value="123"/>
    </bean>

    <!--配置ProcessEngineConfiguration-->
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <!--数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--配置事务-->
        <property name="transactionManager" ref="transactionManager"/>
        <!--数据生成策略    true   false   create   drop-create -->
        <property name="databaseSchemaUpdate" value="true"/>
    </bean>

    <!--配置ProcessEngine-->
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
    </bean>

    <!--配置RepositoryService-->
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
    <!--配置RuntimeService-->
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
    <!--配置TaskService-->
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
    <!--配置HistoryService-->
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>

    <!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
</beans>

步骤三:测试Activiti

@RunWith(SpringJUnit4ClassRunner.class)     //测试方式  junit4.12+
@ContextConfiguration("classpath:activiti-spring.xml")   //配置
public class ActivitiSpringTest {
    @Resource
    private RepositoryService repositoryService;
    @Resource
    private RuntimeService runtimeService;


    /**
     * 测试流程部署
     */
    @Test
    public void deployment(){
        repositoryService.createDeployment()
                .addClasspathResource("amedical/medical.bpmn")
                .name("测试Spring流程部署")
                .deploy();
    }
}

执行效果:

 

posted @ 2020-04-09 15:07  怀鑫  阅读(1224)  评论(0编辑  收藏  举报