<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-engineartifactId>
<version>6.0.0version>
dependency>
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
public class ActivitiTest {
@Test
public void initProcessEngine(){
//创建引擎配置对象
ProcessEngineConfiguration configration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
//创建流程引擎对象
//目标生成数据库表
configration.setJdbcUrl("jdbc:mysql://172.20.10.10:3306/activitydemo");
configration.setJdbcDriver("com.mysql.jdbc.Driver");
configration.setJdbcUsername("root");
configration.setJdbcPassword("root");
//设置表的生成策略
configration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
ProcessEngine processEngine = configration.buildProcessEngine();
System.out.println(processEngine.getName());
}
/**
* 数据源的配置在activiti.cfg.xml 中
*/
@Test
public void initProcessEngine2(){
ProcessEngineConfiguration configration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
ProcessEngine engine = configration.buildProcessEngine();
System.out.println("初始化流引擎对象成功"+engine.getName());
}
}
resources/activiti.cfg.xml
<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/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">
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://172.20.10.10:3306/activitydemo">property>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver">property>
<property name="jdbcUsername" value="root">property>
<property name="jdbcPassword" value="root">property>
<property name="databaseSchemaUpdate" value="true">property>
bean>
beans>
https://blog.csdn.net/m0_38001814/article/details/104253357
// 删除当前的task
managementService.executeCommand(new DeleteTaskCmd(task.getId()));
// 将当前的task设置为想要退回的节点
managementService.executeCommand(new JumpCmd(task.getId()));
public class DeleteTaskCmd extends NeedsActiveTaskCmd<String> {
public DeleteTaskCmd(String taskId){
super(taskId);
}
public String execute(CommandContext commandContext, TaskEntity currentTask){
TaskEntityManagerImpl taskEntityManager = (TaskEntityManagerImpl)commandContext.getTaskEntityManager();
// 获取当前任务的执行对象实例
ExecutionEntity executionEntity = currentTask.getExecution();
// 删除当前任务,来源任务
taskEntityManager.deleteTask(currentTask, "jumpReason", false, false);
// 返回当前任务的执行对象id
return executionEntity.getId();
}
public class JumpCmd implements Command<Void> {
/**
* 目标节点对象
*/
private FlowNode flowElement;
/**
* 当前任务执行id
*/
private String executionId;
public SetFLowNodeAndGoCmd(FlowNode flowElement,String executionId){
this.flowElement = flowElement;
this.executionId = executionId;
}
public Void execute(CommandContext commandContext){
// 获取目标节点的来源连线
List<SequenceFlow> flows = flowElement.getIncomingFlows();
if(flows==null || flows.size()<1){
throw new ActivitiException("回退错误,目标节点没有来源连线");
}
// 随便选一条目标节点的入线来执行,使当前执行计划为:从所选择的流程线流转到目标节点,实现跳转
ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(executionId);
executionEntity.setCurrentFlowElement(flows.get(0));
commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
return null;
}