package com.ycl.activiti; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; public class Activiti7Test { //部署流程 @Test public void test1(){ //通过getDefaut方法获取流程引擎对象会加载resources目录下的activit.cfg.xml ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //完成流程部署操作通过repositoryService对象完成 RepositoryService repositoryService = processEngine.getRepositoryService(); //完成部署 Deployment deploy = repositoryService.createDeployment() .addClasspathResource("flow/test.bpmn20.xml") .name("测试流程") .deploy(); System.out.println(deploy.getId()); System.out.println(deploy.getName()); } //发起流程 @Test public void test2(){ ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); //发起流程,需要通过runtimeService实现 RuntimeService runtimeService = engine.getRuntimeService(); //赋值 Map map = new HashMap<>(); map.put("assign1","zhangsan"); map.put("assign2","lisi"); //对应act_re_procdef表 ProcessInstance processInstance = runtimeService.startProcessInstanceById("test123:1:2503",map); System.out.println("processInstance.getId() ="+processInstance.getId()); System.out.println("processInstance.getDeploymentId() ="+processInstance.getDeploymentId()); System.out.println("processInstance.getDescription() ="+processInstance.getDescription()); } }