当前位置:   article > 正文

org.activiti.engine.impl.RuntimeServiceImpl#startProcessInstanceByKey

org.activiti.engine.impl.RuntimeServiceImpl#startProcessInstanceByKey

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:

  1. 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.

  2. 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:

 
  1. import org.activiti.engine.RuntimeService;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Service;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. @Service
  7. public class ProcessService {
  8. @Autowired
  9. private RuntimeService runtimeService;
  10. public void startProcessInstanceByKey(String processDefinitionKey) {
  11. // Define process variables
  12. Map<String, Object> variables = new HashMap<>();
  13. variables.put("variable1", "value1");
  14. variables.put("variable2", 123);
  15. // Start process instance
  16. runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
  17. }
  18. }

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.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/126679?site
推荐阅读
相关标签
  

闽ICP备14008679号