zhouweixin / activiti-demo-1 Goto Github PK
View Code? Open in Web Editor NEWactiviti的第一个实例
activiti的第一个实例
- src -- source folder, 用来存放各种源文件
- lib -- folder, 存放各种jar包
- resource -- source folder, 配置文件和相应的资源文件
- activiti
- log4j
- mysql-connnector-java
- activiti.cfg.xml -- activiti默认加载的配置文件, 主要是对数据库的配置, 这里用的是mysql数据库, 所以需要提前创建act数据库
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 流程引擎配置的bean -->
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/act" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
- log4j.properties -- 日志文件默认加载的配置文件
log4j.rootLogger=INFO, stdout
# Console Appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n
# Custom tweaks
log4j.logger.com.codahale.metrics=WARN
log4j.logger.com.ryantenney=WARN
log4j.logger.com.zaxxer=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.engine.internal=WARN
log4j.logger.org.hibernate.validator=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.springframework.web=WARN
log4j.logger.org.springframework.security=WARN
- MyProcess.bpmn -- 创建的一个流程, 任意创建一个流程都可运行
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="task1"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="task2"></userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="70.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="150.0" y="110.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="300.0" y="110.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="450.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="105.0" y="137.0"></omgdi:waypoint>
<omgdi:waypoint x="150.0" y="137.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="255.0" y="137.0"></omgdi:waypoint>
<omgdi:waypoint x="300.0" y="137.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="405.0" y="137.0"></omgdi:waypoint>
<omgdi:waypoint x="450.0" y="137.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
public class Demo1 {
/**
* 部署流程
*/
@Test
public void deployProcess() {
// 默认去加载resource下的activiti.cfg.xml配置文件,可以查看源码
// 通过默认的方法创建流程引擎:这里主要是数据库的配置
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 【存储服务】
RepositoryService repositoryService = engine.getRepositoryService();
// 部署流程文件:文件内容和流程图存储到数据表【act_ge_bytearray】中
repositoryService.createDeployment().addClasspathResource("MyProcess.bpmn").deploy();
}
/**
* 执行流程
*/
@Test
public void doProcess() {
// 通过默认的方法创建流程引擎:这里主要是数据库的配置
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 【运行时服务】
RuntimeService runService = engine.getRuntimeService();
// 【任务服务】
TaskService taskService = engine.getTaskService();
// 启动流程
ProcessInstance processInstance = runService.startProcessInstanceByKey("myProcess");
// 普通员工完成请假的任务
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
System.out.println("当前流程节点:" + task.getName());
taskService.complete(task.getId());
// 经理审核任务
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
System.out.println("当前流程节点:" + task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
System.out.println("流程结束后:" + task);
engine.close();
System.exit(0);
}
}
- 第一次执行会比较慢, 因为程序会在act数据库里创建28张activiti用到的表
- 创建一个流程实例, 并按次序执行任务1和任务2
结束
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.