那么多博客,我总觉都得没说好如何快速在eclipse搭建跑起来。
一、安装插件:
1:Help-》Install New Sofeware-》add
Name:Activiti Designer
Location:http://activiti.org/designer/update/
如图:
然后安装
重启eclipse。。。
二、搭建工作流:
1、提供一个mysql
2、新建MAVEN工程:
3、添加resource文件夹:
4、pom.xml引入依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.open</groupId>
<artifactId>activiti-demo01</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>activiti-demo01</name>
<properties>
<activiti-version>5.18.0</activiti-version>
</properties>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>${activiti-version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>${activiti-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.USER_LIBRARY/Activiti Designer Extensions</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
</plugins>
</build>
</project>
4、在resource下面,添加active-digrams
5、画图
6、在resource下面编写配置文件activiti.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/voj?useUnicode=true&characterEncoding=utf8"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="root"></property>
<!-- 没有表创建表 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
</beans>
7、java代码测试
package com.open.activeti_demo01;
import java.util.List;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
/**
* Hello world!
*
*/
public class App
{
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程定义
*/
@Test
public void deployment() {
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署相关的Service
.createDeployment()//创建一个部署对象
.name("demoProcess")//添加部署的名称
.addClasspathResource("MyProcess.bpmn")//从classpath下加载资源,一次一个
.deploy();//完成部署
System.out.println("部署ID"+deployment.getId());//1
System.out.println("部署名称"+deployment.getName());
}
/**
*启动流程实例
*/
@Test
public void startProcessInstance() {
String processDefinitionKey = "myProcess";
ProcessInstance processInstance = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
.startProcessInstanceByKey(processDefinitionKey);//根据Key值来查询流程,也可以根据ID
System.out.println("流程实例ID:"+processInstance.getId()); //2501
//对应数据库act_ru_execution
System.out.println("流程定义ID:"+processInstance.getProcessDefinitionId()); //helloword:1:4
//对应数据库act_re_deployment
}
/**
* 查询当前个人的任务
*/
@Test
public void fingByPerson() {
String assignee = "user1";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
.taskAssignee(assignee)//指定个人任务查询,指定代理人
.list();//以list形式记录对象
if(list != null && list.size()>0) {
for(Task task:list) {
System.out.println("任务ID:"+task.getId());//22504
System.out.println("任务名称:"+task.getName());//提交申请
System.out.println("任务的创建时间:"+task.getCreateTime());//:Wed Nov 14 17:02:43 CST 2018
System.out.println("任务的代理人:"+task.getAssignee());//staff1
System.out.println("流程实例ID:"+task.getProcessInstanceId());//22501
System.out.println("执行对象ID:"+task.getExecutionId());//22501
System.out.println("流程定义ID:"+task.getProcessDefinitionId());//demoProcess:1:20004
}
}
}
/**
* 完成个人任务
*/
@Test
public void complete() {
String taskId = "32508";
processEngine.getTaskService()
.complete(taskId );
System.out.println("完成任务ID:"+taskId);
}
}
8、右键执行测试结果
9、完成工程结构