赞
踩
The org.activiti.engine.impl.RuntimeServiceImpl#startProcessInstanceByKey(String, Map<String, Object>)
method is used to start a new process instance in the Activiti engine based on the provided process definition key and process variables.
Here's how you can use this method:
Process Definition Key: Pass the key of the process definition you want to start as the first parameter. This key is defined in your BPMN XML file.
Process Variables: Pass a map of process variables as the second parameter. These variables can be used within your process definition to control its behavior.
Here's an example of how to use this method:
- import org.activiti.engine.RuntimeService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
-
- import java.util.HashMap;
- import java.util.Map;
-
- @Service
- public class ProcessService {
-
- @Autowired
- private RuntimeService runtimeService;
-
- public void startProcessInstanceByKey(String processDefinitionKey) {
- // Define process variables
- Map<String, Object> variables = new HashMap<>();
- variables.put("variable1", "value1");
- variables.put("variable2", 123);
-
- // Start process instance
- runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
- }
- }
In this example:
processDefinitionKey
is the key of the process definition you want to start.variables
is a map containing process variables. These variables will be available within the process instance and can be used in BPMN tasks, gateways, etc.Make sure to replace "variable1"
, "value1"
, "variable2"
, and 123
with your actual variable names and values.
Remember that the process definition key must correspond to an existing process definition deployed in your Activiti engine. If the process definition contains any required variables, make sure to provide them in the variables
map.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。