Activiti---demo
【请假流程】
0、初始化表
1、画流程图
1.1、画流程图
1.2、设置办理人
1.3、设置流程id、name
【空白区域】
2、部署流程定义
2.1、将流程图重命名为.xml文件,再保存png文件,再将.xml文件改回bpmn文件;
3、启动流程
4、查询任务
5、办理任务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | <? 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.an</ groupId > < artifactId >activitidemo</ artifactId > < version >1.0-SNAPSHOT</ version > < properties > < spring.version >4.3.17.RELEASE</ spring.version > < mysql.version >5.1.10</ mysql.version > < activiti.version >5.22.0</ activiti.version > < mybatis.version >3.4.6</ mybatis.version > < log4j.version >1.2.17</ log4j.version > </ properties > < dependencies > < 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 > <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> < dependency > < groupId >mysql</ groupId > < artifactId >mysql-connector-java</ artifactId > < version >8.0.21</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-aspects</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-aop</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-context</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-core</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-beans</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-expression</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-jdbc</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-tx</ artifactId > < version >${spring.version}</ version > </ dependency > < dependency > < groupId >org.mybatis</ groupId > < artifactId >mybatis</ artifactId > < version >${mybatis.version}</ version > </ dependency > < dependency > < groupId >log4j</ groupId > < artifactId >log4j</ artifactId > < version >${log4j.version}</ version > </ dependency > < dependency > < groupId >org.slf4j</ groupId > < artifactId >slf4j-api</ artifactId > < version >1.7.25</ version > </ dependency > < dependency > < groupId >org.slf4j</ groupId > < artifactId >slf4j-simple</ artifactId > < version >1.7.25</ version > </ dependency > <!-- https://mvnrepository.com/artifact/junit/junit --> < dependency > < groupId >junit</ groupId > < artifactId >junit</ artifactId > < version >4.8</ version > < scope >test</ scope > </ dependency > < dependency > < groupId >org.junit.jupiter</ groupId > < artifactId >junit-jupiter-api</ artifactId > < version >RELEASE</ version > < scope >compile</ scope > </ dependency > </ dependencies > < build > < plugins > < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-compiler-plugin</ artifactId > < version >3.7.0</ version > < configuration > < source >1.8</ source > < target >1.8</ target > </ configuration > </ plugin > </ plugins > </ build > </ project > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | log4j.rootLogger=INFO,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n log4j.logger.com.codahale.metrics=DEBUG log4j.logger.com.ryantenney=DEBUG log4j.logger.com.zaxxer=DEBUG log4j.logger.org.apache=DEBUG log4j.logger.org.hibernate=DEBUG log4j.logger.org.hibernate.engine.internal=DEBUG log4j.logger.org.hibernate.engine.validator=DEBUG log4j.logger.org.springframework=DEBUG log4j.logger.org.springframework.web=DEBUG log4j.logger.org.springframework.security=DEBUG |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <? xml version="1.0" encoding="UTF-8"?> < beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> < bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> < property name="jdbcDriver" value="com.mysql.jdbc.Driver"/> < property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useSSL=false&allowPublicKeyRetrieval=true"/> < property name="jdbcUsername" value="root"/> < property name="jdbcPassword" value="123456"/> < property name="databaseSchemaUpdate" value="true"/> </ bean > </ beans > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | package com.an.init; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.ProcessEngines; import org.junit.jupiter.api.Test; import org.springframework.jdbc.datasource.DriverManagerDataSource; public class InitTables { @Test public static void initOne(){ DriverManagerDataSource dataSource=new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/activiti?useSSL=false"); dataSource.setUsername("root"); dataSource.setPassword("123456"); ProcessEngineConfiguration processEngineConfiguration=ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); //数据源 processEngineConfiguration.setDataSource(dataSource); //配置表的初始化方式 processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //获取流程引擎 ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine(); System.out.println(processEngine); } @Test public static void initTwo(){ ProcessEngineConfiguration processEngineConfiguration=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("/activiti.cfg.xml"); processEngineConfiguration.buildProcessEngine(); } @Test public static void initThree(){ ProcessEngines.getDefaultProcessEngine(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | package com.an.helloworld; import org.activiti.engine.*; import org.activiti.engine.repository.Deployment; import org.activiti.engine.task.Task; import org.junit.jupiter.api.Test; import java.util.List; public class HelloWorld { private ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine(); /** * 流程部署 */ @Test public void deployProcess(){ RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment().name("请假流程") .addClasspathResource("helloworld.bpmn") .addClasspathResource("helloworld.png") .deploy(); System.out.println("部署成功!流程部署id:"+deployment.getId()); } /** * 启动流程 */ @Test public void startProcess(){ RuntimeService runtimeService = processEngine.getRuntimeService(); runtimeService.startProcessInstanceById("helloworld:1:4"); System.out.println("流程启动成功!"); } /** * 查询任务 */ @Test public void findTasks(){ TaskService taskService = processEngine.getTaskService(); List< Task > taskList = taskService.createTaskQuery().taskAssignee("王五").list(); for (Task t:taskList) { System.out.println("任务ID:"+t.getId()); System.out.println("流程实例ID:"+t.getProcessInstanceId()); System.out.println("执行实例ID:"+t.getExecutionId()); System.out.println("流程定义ID:"+t.getProcessDefinitionId()); System.out.println("任务名称:"+t.getName()); System.out.println("任务办理人:"+t.getAssignee()); } } /** * 办理任务 */ @Test public void doTask(){ TaskService taskService = processEngine.getTaskService(); taskService.complete("7502"); System.out.println("王五办理任务"); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)