activiti6执行Python脚本

activiti6执行Python脚本,第1张

activiti6执行Python脚本

activiti6中的脚本任务可以通过scriptFormat指定脚本格式来执行对应的脚本,scriptFormat属性的值必须是与JSR-223(Java平台的脚本编写)兼容的名称。

需要执行python脚本需要选择的脚本格式为jython

需要引入的jar:


   org.activiti
   activiti-spring-boot-starter-basic
   6.0.0


   org.python
   jython
   2.7.2

1.创建一个简单的流程如下:

 脚本任务中的属性配置为:

整个流程的ID设置为python_test_1



  
    
      SequenceFlow_0bdle5t
    
    
    
      SequenceFlow_0h63l8b
    
    
    
      SequenceFlow_0bdle5t
      SequenceFlow_0h63l8b
      print("hello 2022!!!!")
    
  
  
    
      
        
        
          
        
      
      
        
        
      
      
        
        
          
        
      
      
        
        
      
      
        
      
    
  

 2.在Controller中的调用方法如下:

   @GetMapping("/api/bpmn/python_test")
    public void mysql_test(){
        Deployment deployment = repositoryService.createDeployment().name("Python测试任务").addClasspathResource("processes/pythonTest_01.bpmn").deploy();
        log.error("部署 ID is:{} name is:{}", deployment.getId(), deployment.getName());
        Properties props = new Properties();
        props.put("python.home", "path to the Lib folder");
        props.put("python.console.encoding", "UTF-8");
        props.put("python.security.respectJavaAccessibility", "false");
        props.put("python.import.site", "false");
        Properties preprops = System.getProperties();
        PythonInterpreter.initialize(preprops, props, new String[0]);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("python_test_1");
        log.error("流程实例ID is:{}, n流程定义ID is:{}, ", processInstance.getId(), processInstance.getProcessDefinitionId());
    }

3.运行结果:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5708095.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存