https://www.activiti.org/download-links
快速开始
https://www.activiti.org/quick-start
用户指南
https://www.activiti.org/userguide/
1.根据快速开始操作,创建maven工程,配置相关依赖, $actVer改为6.0.0 本例使用mysql替代h2
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
2.加入配置文件/src/main/resources/log4j.properties
log4j.rootLogger=DEBUG, ACT
log4j.appender.ACT=org.apache.log4j.ConsoleAppender
log4j.appender.ACT.layout=org.apache.log4j.PatternLayout
log4j.appender.ACT.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x – %m%n
3.mysql创建数据库并连接

4.获取流程引擎对象ProcessEngine
4.1.通过代码设置
// 引擎配置
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl("jdbc:mysql://localhost:3306/activiti").setJdbcUsername("root")
.setJdbcPassword("pwd")
.setJdbcDriver("com.mysql.jdbc.Driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
// 获取流程引擎对象
ProcessEngine processEngine = cfg.buildProcessEngine();
4.2.通过activiti.cfg.xml配置文件
ProcessEngineConfiguration cfg = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = cfg.buildProcessEngine();
配置文件activiti.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd”>
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti"/>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUsername" value="root"/>
<property name="jdbcPassword" value="pwd"/>
<property name="databaseSchemaUpdate" value="true"/>
</bean>
执行后初始化数据表如下

5.安装BPM插件
5.1 IDEA搜索并安装BPM插件 Business Process Management

加入示例中的xml /src/main/resources/onboarding.bpmn20.xml
打开xml可以看到流程图

5.2.IDEA的BPM插件使用体检较差,建议使用eclipse插件
安装插件 Install New Software http://activiti.org/designer/update/
Activiti 5.10支持直接部署扩展名为bpmn的流程文件,设计器打开如下:

6.下面就可以为所欲为了
// 启动流程
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("myProcess");
System.out.println("process id" + pi.getId());
System.out.println("process name" + pi.getName());
// 获取任务
TaskService taskService = processEngine.getTaskService();
List<Task> list = taskService.createTaskQuery().taskAssignee("lili").list();
System.out.println("任务个数" + list.size());
if (list != null && list.size() > 0) {
for (Task t : list) {
System.out.print(t.getId() + ",");
System.out.print(t.getName() + ",");
System.out.print(t.getAssignee() + ",");
System.out.println(t.getProcessInstanceId());
}
}