activti简单使用

作者 : 开心源码 本文共6174个字,预计阅读时间需要16分钟 发布时间: 2022-05-13 共254人阅读
创立springboot项目

创立一个springboot项目引入相关的依赖,引入activiti 需要的相关依赖。

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>com.activiti.org</groupId>    <artifactId>activiti</artifactId>    <version>1.0-SNAPSHOT</version>    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.1.RELEASE</version>        <relativePath/>    </parent>    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>        <java.version>1.8</java.version>        <activiti.version>5.22.0</activiti.version>        <h2.version>1.4.180</h2.version>        <junit.version>4.10</junit.version>        <mockito.version>1.10.19</mockito.version>        <powermock.version>1.6.6</powermock.version>    </properties>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-test</artifactId>        </dependency>        <!-- TEST begin -->        <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>${junit.version}</version>        </dependency>        <dependency>            <groupId>org.mockito</groupId>            <artifactId>mockito-core</artifactId>            <version>${mockito.version}</version>        </dependency>        <dependency>            <groupId>org.powermock</groupId>            <artifactId>powermock-module-junit4</artifactId>            <version>${powermock.version}</version>        </dependency>        <dependency>            <groupId>org.powermock</groupId>            <artifactId>powermock-api-mockito</artifactId>            <version>${powermock.version}</version>            <exclusions>                <exclusion>                    <groupId>org.mockito</groupId>                    <artifactId>mockito-all</artifactId>                </exclusion>            </exclusions>        </dependency>        <dependency>            <groupId>org.springframework</groupId>            <artifactId>spring-test</artifactId>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupId>com.h2database</groupId>            <artifactId>h2</artifactId>            <version>${h2.version}</version>        </dependency>        <dependency>            <groupId>org.dbunit</groupId>            <artifactId>dbunit</artifactId>            <version>2.4.8</version>        </dependency>        <dependency>            <groupId>org.activiti</groupId>            <artifactId>activiti-engine</artifactId>            <version>${activiti.version}</version>        </dependency>        <dependency>            <groupId>org.activiti</groupId>            <artifactId>activiti-spring</artifactId>            <version>${activiti.version}</version>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build></project>
idea 上安装activiti 插件

可以参考这篇文章:安装activiti 插件

使用的效果如图:

image.png

生成的文件是以bpmn结尾,同时我们可以把bpmn文件转化成xml 文件,生成的xml文件如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn"             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"             expressionLanguage="http://www.w3.org/1999/XPath"             id="m1533434256601" name="" targetNamespace="http://www.activiti.org/test"             typeLanguage="http://www.w3.org/2001/XMLSchema">    <process id="myProcess_1" isClosed="false" isExecutable="true" processType="None">        <startEvent activiti:formKey="leave" activiti:initiator="xixi" id="start" name="StartEvent"/>        <userTask activiti:assignee="yuxi" activiti:exclusive="true" id="_3" name="审核"/>        <endEvent id="end" name="EndEvent"/>        <sequenceFlow id="_5" sourceRef="start" targetRef="_3"/>        <sequenceFlow id="_6" sourceRef="_3" targetRef="end"/>    </process>    <bpmndi:BPMNDiagram            documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0"            id="Diagram-_1" name="New Diagram">        <bpmndi:BPMNPlane bpmnElement="myProcess_1">            <bpmndi:BPMNShape bpmnElement="start" id="Shape-start">                <omgdc:Bounds height="32.0" width="32.0" x="175.0" y="50.0"/>                <bpmndi:BPMNLabel>                    <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>                </bpmndi:BPMNLabel>            </bpmndi:BPMNShape>            <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">                <omgdc:Bounds height="55.0" width="85.0" x="145.0" y="160.0"/>                <bpmndi:BPMNLabel>                    <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>                </bpmndi:BPMNLabel>            </bpmndi:BPMNShape>            <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">                <omgdc:Bounds height="32.0" width="32.0" x="170.0" y="310.0"/>                <bpmndi:BPMNLabel>                    <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>                </bpmndi:BPMNLabel>            </bpmndi:BPMNShape>            <bpmndi:BPMNEdge bpmnElement="_5" id="BPMNEdge__5" sourceElement="_2" targetElement="_3">                <omgdi:waypoint x="191.0" y="82.0"/>                <omgdi:waypoint x="191.0" y="160.0"/>                <bpmndi:BPMNLabel>                    <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>                </bpmndi:BPMNLabel>            </bpmndi:BPMNEdge>            <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="_3" targetElement="_4">                <omgdi:waypoint x="186.0" y="215.0"/>                <omgdi:waypoint x="186.0" y="310.0"/>                <bpmndi:BPMNLabel>                    <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>                </bpmndi:BPMNLabel>            </bpmndi:BPMNEdge>        </bpmndi:BPMNPlane>    </bpmndi:BPMNDiagram></definitions>
启动一个简单的流程
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)public class VeryProcessTest {    ProcessEngine processEngine;    @Before    public void testBefore() {        // 创立流程引擎        processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()            .buildProcessEngine();    }    @Test    public void test() {        //部署流程定义文件        RepositoryService repositoryService = processEngine.getRepositoryService();        Deployment deploy = processEngine.getRepositoryService()            .createDeployment()            .addClasspathResource("leave.bpmn")            .deploy();        assertNotNull(deploy);        RuntimeService runtimeService = processEngine.getRuntimeService();        //创立流程定义        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(            deploy.getId()).singleResult();        //初始化流程        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinition.getKey());        assertNotNull(processInstance);    }}
  • 需要注意的是这里使用的是内存数据库,可以参考pom依赖文件。
  • 需要注意activiti 部署流程资源有很多种方式,可以选择你比较喜欢的。
    流程部署方式
    创立一个流程的步骤是:
    获取流程引擎(ProcessEngine)–>部署流程定义文件–>创立流程定义—>初始化具体流程
说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » activti简单使用

发表回复