工作流——activiti
1.导入依赖
<!-- activiti工作流 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.14</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.14</version>
</dependency>
2.配置xml
a.新建spring-activiti.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="activityFontName" value="微软雅黑"></property> <!-- 引入druid数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 引入spring事务管理 -->
<property name="transactionManager" ref="txManager"></property>
<!-- 建表策略 -->
<property name="databaseSchemaUpdate" value="true"></property>
<!-- 历史控制级别 -->
<property name="history" value="full"></property> <!-- 自动部署 -->
<property name="deploymentResources">
<list>
<value>classpath*:MyProcess.bpmn</value>
</list>
</property>
</bean> <bean id="processEngineFactoryBean" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"></property>
</bean> <bean id="repositoryService" factory-bean="processEngineFactoryBean" factory-method="getRepositoryService"></bean>
<bean id="runtimeService" factory-bean="processEngineFactoryBean" factory-method="getRuntimeService"></bean>
<bean id="taskService" factory-bean="processEngineFactoryBean" factory-method="getTaskService"></bean>
<bean id="historyService" factory-bean="processEngineFactoryBean" factory-method="getHistoryService"></bean>
<bean id="formService" factory-bean="processEngineFactoryBean" factory-method="getFormService"></bean>
<bean id="identityService" factory-bean="processEngineFactoryBean" factory-method="getIdentityService"></bean>
<bean id="managementService" factory-bean="processEngineFactoryBean" factory-method="getManagementService"></bean> </beans>
注意:其中 dataSource 和 txManager 为 spring-mybatis.xml 中配置的 “数据源(数据库连接池)” 和 “事务管理”,所以不能在web.xml中引入,而应在spring-mybatis.xml中引入
b.在 spring-mybatis.xml 引入 spring-activiti.xml 配置
<!-- 导入activiti工作流配置 -->
<import resource="spring-activiti.xml"/>
3.绘制流程图
a.eclipse 中安装插件: help —> Install New Software —> Add
Name:activiti
Location:http://activiti.org/designer/update/
b.新建流程图:新建 MyProcess.bpmn


4.使用
a.在Service中使用
@Service
public class ProcessService { public final static String PROCESS_ID = "myProcess"; //流程储存服务组件
@Resource
RepositoryService repositoryService; //运行时服务组件
@Resource
RuntimeService runtimeService; //流程中的任务TASK组件
@Resource
TaskService taskService; //部署流程(若xml已配置自动部署,则不需要此方法)
public void deployProcess(){
// 部署流程,只要是符合BPMN2规范的XML文件,理论上都可以被ACTIVITI部署
repositoryService.createDeployment().addClasspathResource("MyProcess.bpmn").deploy();
} //启动流程
public void startProcess(){
// 开启流程,参数是流程的ID
runtimeService.startProcessInstanceByKey(PROCESS_ID);
} //根据Assignee查询task
public List<Task> findTaskByAssignee(String assignee){
List<Task> taskList = taskService.createTaskQuery().
taskAssignee(assignee). //根据办理人查询
orderByTaskCreateTime().asc(). //根据创建时间升序排列
list(); //返回列表 for(Task task : taskList){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("=========================================");
} return taskList;
} //完成任务
//variables 为流程变量,对应bpmn 中 Condition 设置的 ${message=='不重要'}
public void completeProcess(String taskId, Map<String, Object> variables){
taskService.complete(taskId, variables);
System.out.println("完成任务ID:"+taskId);
}
}
b.在Controller中测试
//提交流程
@RequestMapping("submitProcess")
public @ResponseBody String submitProcess(HttpServletRequest request, HttpServletResponse response){
processService.startProcess();
return "提交流程成功";
} //部长审批
@RequestMapping("departmentProcess")
public @ResponseBody String departmentProcess(HttpServletRequest request, HttpServletResponse response){
List<Task> taskIdList = processService.findTaskByAssignee("department");
for(Task task : taskIdList){
String taskId = task.getId();
processService.completeProcess(taskId, null);
}
return "部长审批成功";
} //副总审批
@RequestMapping("managerProcess")
public @ResponseBody String managerProcess(HttpServletRequest request, HttpServletResponse response){
List<Task> taskIdList = processService.findTaskByAssignee("manager");
for(Task task : taskIdList){
String taskId = task.getId();
processService.completeProcess(taskId, null);
}
return "副总审批成功";
}
工作流——activiti的更多相关文章
- 工作流Activiti新手入门学习路线整理
写在前面: 最近项目中使用到了工作流,虽然此部分不是自己需要完成的,但是也涉及到了要调用写的接口.正好有时间,就了解下,以便之后能在其他项目中用到时,不至于什么都不知道什么都不了解. 这里就主要整理下 ...
- (2)java程序走一遍工作流activiti
工作流从流程定义到创建一个流程实例完成执行步骤 使用activi-designer创建一个流程定义(.bpmn结尾的文件) 将定义好的流程定义和生成的png图片通过RepositoryService( ...
- java工作流activiti的步骤
链接:activiti 表名称的解释 工作流从流程定义到创建一个流程实例完成执行步骤(省略bpmn的画法) 工作流的所有操作都是使用流程引擎来进行操作的,流程引擎只是存储流程的过程,而不存储具体的业务 ...
- springboot~工作流activiti的搭建
概念 工作流产品使用activiti的算是比较多了,自带了一套UI界面,可以直接使用,用来设计流程,下面简单总结一下它的步骤: 1 设计模型 2 发布为流程,一个模型可以发布多个版本的流程 3 建立一 ...
- 工作流--Activiti
一.工作流 1.工作流介绍 工作流(Workflow),就是通过计算机对业务流程自动化执行管理.它主要解决的是“使在多个参与者 之间按照某种预定义的规则自动进行传递文档.信息或任务的过程,从而实现某 ...
- 工作流Activiti的学习总结(十二) activiti官方十分钟快速学习 (zhuan)
http://topmanopensource.iteye.com/blog/1315341 ***************************************************** ...
- JeeSite 工作流Activiti的应用实例
新建流程模型 在线办公-流程管理-模型管理-新建模型 点击“提交”后会立即跳转到“流程在线设计器”页面,请看下一章节 在线流程设计器 在线办公流程管理模型管理模型管理编辑 整体流程图 mat ...
- 工作流Activiti框架中表单的使用!详细解析内置表单和外置表单的渲染
Activiti中的表单 Activiti提供了一种方便而且灵活的方式在业务流程中以手工方式添加表单 对表单的支持有2种方式: 通过表单属性对内置表单进行渲染 通过表单属性对外置表单进行渲染 表单属性 ...
- 工作流Activiti框架中的LDAP组件使用详解!实现对工作流目录信息的分布式访问及访问控制
Activiti集成LDAP简介 企业在LDAP系统中保存了用户和群组信息,Activiti提供了一种解决方案,通过简单的配置就可以让activit连接LDAP 用法 要想在项目中集成LDAP,需要在 ...
随机推荐
- Shell脚本统计文件行数
Shell脚本统计文件行数 转自 http://www.jb51.net/article/61943.htm 示例:row_count.sh文件 awk '{print NR}' row_cou ...
- <HTML> 模块
一些元素 <q>元素 用于引用, quote 浏览器一般会负责加上双引号,但是不是所有的浏览器都会在<q>元素的内容两边加双引号. <blockquote>元素 用 ...
- mysql 设置skip_name_resolve参数 日志 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode
[环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.25-enterprise-commercial-advanced-log MySQL Enterprise ...
- 一个网站SQL注入的案例
网站的页面提交参数做了md5转换,而且参数会带入两个SQL语句中执行. 注入是肯定存在的,但是SQLMAP怎么都跑不出来(可能原因是其中有个SQL语句总是报错). 尝试手工,发现 order by 报 ...
- 移除文件(git rm)
git rm`命令会把文件从已跟踪列表(及暂存区)中移除,并且移除把文件从工作目录中移除,这样下一次你就不会在未跟踪文件列表中看到这些文件了. 如果你只是简单的把文件从工作目录移除,而没有使用git ...
- day 21 - 2 练习
三级菜单 menu = { '北京': { '海淀': { '五道口': { 'soho': {}, 'google': {}, '网易': {} }, '中关村': { '爱奇艺': {}, '汽车 ...
- ubuntu 装机必备
在github上下载高博的slambook(https://github.com/gaoxiang12/slambook)在3rdparty文件夹中有安装包. 1. 安装Eigen库 sudo apt ...
- Linux的简单命令
Linux的简单命令 1.更改linux服务器的登录密码 成功登录后输入命令: passwd 然后按照提示操作即可 2.在当前路径下新建文件夹:mkdir 新建文件夹名 3.解压和压缩文件tar.gz ...
- cocos2dx-lua调用C++
文参考:https://www.cnblogs.com/xiaonanxia/p/4987856.html 上面的文章是IOS版教程,用4部分说明原理,1部分说操作步骤. 这里用window VS20 ...
- 实验一《Java开发环境的熟悉》_实验报告
实验一<Java开发环境的熟悉>_实验报告 一.实验内容与主要步骤 1.Linux系统命令行下java程序开发 实验要求 1 建立"自己学号exp1"的目录 2 在&q ...