Java Activiti(8)--監聽器

來源:互聯網
上載者:User
一、執行監聽器

1、建立監聽

/** * 執行監聽器 * Created by Administrator on 2017/10/12. */public class MyExecutionListener implements ExecutionListener {    @Override    public void notify(DelegateExecution execution) {        System.out.println("notify====getEventName=====" + execution.getEventName());    }}

2、建立流程:

3、在start處添加監聽

4、產生三個檔案

5、部署流程

 @Test    public void deployLeave() throws Exception {        DeploymentBuilder builder = processEngine.getRepositoryService().createDeployment();        builder.addClasspathResource("flow/executionListener.bpmn");        builder.addClasspathResource("flow/executionListener.png");        builder.name("執行監聽器報銷流程部署");        Deployment deploy = builder.deploy();        System.out.println("deploy.getId()==" + deploy.getId());    }

6、啟動流程執行個體時,添加變數

@Test    public void startProcessInstanceByKey() throws Exception {        //String processDefinitionKey = "grouptask";        String processInstanceId = "72501";        Map<String, Object> variable = new HashMap<String, Object>();        variable.put("amount", "300元");        variable.put("reason", "出差");        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processInstanceId,variable);        System.out.println("processInstance.getId()===" + processInstance.getId());        System.out.println("processInstance.getProcessDefinitionId()===" + processInstance.getProcessDefinitionId());    }

7、完成任務

@Test    public void dealPersonalTask() throws Exception {        String taskId = "75011";        processEngine.getTaskService().complete(taskId);    }

註:在提交任務與完成任務時,都會觸發監聽事件 二、任務監聽器

1、建立監聽器

public class MyTaskListener1 implements TaskListener {    @Override    public void notify(DelegateTask delegateTask) {        System.out.println(delegateTask.getExecutionId());        Map<String, Object> variables = delegateTask.getVariables();        Set<String> variableNames = delegateTask.getVariableNames();        for(String key : variableNames){            System.out.println(key +":" + delegateTask.getVariable(key));        }        System.out.println("一個任務由" + delegateTask.getName() + "建立了,下一步由" + delegateTask.getAssignee() + "負責辦理");    }}

2、添加create監聽器

—————————————————————————————————————————————————– java架構師項目實戰,高並發叢集分布式,大資料高可用視頻教程,共760G

下載地址:

https://item.taobao.com/item.htm?id=555888526201

01.進階架構師四十二個階段高
02.Java進階系統培訓架構課程148課時
03.Java進階互連網架構師課程
04.Java互連網架構Netty、Nio、Mina等-視頻教程
05.Java進階架構設計2016整理-視頻教程
06.架構師基礎、進階片
07.Java架構師必修linux營運系列課程
08.Java進階系統培訓架構課程116課時
+
hadoop系列教程,java設計模式與資料結構, Spring Cloud微服務, SpringBoot入門

—————————————————————————————————————————————————–

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.