WFMS(工作流管理系统):http://baike.baidu.com/view/977667.htm
WFMC(工作流管理联盟):http://baike.baidu.com/view/2497858.htm
示例项目下载
http://pan.baidu.com/s/1gd3iNfH
环境搭建:
FBI WARNING 两个视频,屏幕录像专家录制,非病毒,本站愿意承担责任,下载完文件请先核对MD5。
1.Eclipse配置Tomcat和部署WEB应用.exe(MD5:81c1dfb994ff5b2094ce0dac244da598)
http://pan.baidu.com/s/1kTgb8PL
2.Activiti项目搭建与Spring集成配置.exe(MD5:3debeec0a00dc061c782ca0cdcc97f7d)
http://pan.baidu.com/s/1sjyKCY5
项目搭建:
Maven项目POM
4.0.2.RELEASE
4.3.4.Final
5.1.29
0.9.1.2
1.2.17
5.15.1
1.2
org.springframework
spring-webmvc
${springframework}
org.springframework
spring-orm
${springframework}
org.springframework
spring-context-support
${springframework}
org.hibernate
hibernate-core
${hibernate}
mysql
mysql-connector-java
${mysql.connector}
c3p0
c3p0
${c3p0}
log4j
log4j
${log4j}
jstl
jstl
${jstl}
org.activiti
activiti-engine
${activiti}
org.activiti
activiti-spring
${activiti}
junit
junit
3.8.1
test
与Spring集成:
activiti.cfg.xml
activiti的API中,最终要的一个接口就是ProcessEngine,获取到ProcessEngine的实例,就获取了activiti体系中的所有api。重要的接口如下:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
ManagementService managementService = processEngine.getManagementService();
IdentityService identityService = processEngine.getIdentityService();
HistoryService historyService = processEngine.getHistoryService();
FormService formService = processEngine.getFormService();
Activiti的服务框架如下
ActivitiController代码
package org.xdemo.example.activiti.controller;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.cmd.GetDeploymentProcessDiagramCmd;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/process")
public class ActivitiController {
@Resource
ProcessEngine engine;
/**
* 列出所有流程模板
*/
@RequestMapping(method = RequestMethod.GET)
public ModelAndView list(ModelAndView mav) {
mav.addObject("list", Util.list());
mav.setViewName("process/template");
return mav;
}
/**
* 部署流程
*/
@RequestMapping("deploy")
public ModelAndView deploy(String processName, ModelAndView mav) {
RepositoryService service = engine.getRepositoryService();
if (null != processName)
service.createDeployment()
.addClasspathResource("diagrams/" + processName).deploy();
List list = service.createProcessDefinitionQuery()
.list();
mav.addObject("list", list);
mav.setViewName("process/deployed");
return mav;
}
/**
* 已部署流程列表
*/
@RequestMapping("deployed")
public ModelAndView deployed(ModelAndView mav) {
RepositoryService service = engine.getRepositoryService();
List list = service.createProcessDefinitionQuery()
.list();
mav.addObject("list", list);
mav.setViewName("process/deployed");
return mav;
}
/**
* 启动一个流程实例
*/
@SuppressWarnings("unchecked")
@RequestMapping("start")
public ModelAndView start(String id, ModelAndView mav) {
RuntimeService service = engine.getRuntimeService();
service.startProcessInstanceById(id);
List list = service.createProcessInstanceQuery()
.list();
mav.addObject("list", list);
mav.setViewName("process/started");
return mav;
}
/**
* 所有已启动流程实例
*/
@RequestMapping("started")
public ModelAndView started(ModelAndView mav) {
RuntimeService service = engine.getRuntimeService();
List list = service.createProcessInstanceQuery()
.list();
mav.addObject("list", list);
mav.setViewName("process/started");
return mav;
}
/**
* 进入任务列表
*/
@RequestMapping("task")
public ModelAndView task(ModelAndView mav){
TaskService service=engine.getTaskService();
List list=service.createTaskQuery().list();
mav.addObject("list", list);
mav.setViewName("process/task");
return mav;
}
/**
*完成当前节点
*/
@RequestMapping("complete")
public ModelAndView complete(ModelAndView mav,String id){
TaskService service=engine.getTaskService();
service.complete(id);
return new ModelAndView("redirect:task");
}
/**
* 所有已启动流程实例
*
* @throws IOException
*/
@RequestMapping("graphics")
public void graphics(String definitionId, String instanceId,
String taskId, ModelAndView mav, HttpServletResponse response)
throws IOException {
response.setContentType("image/png");
Command cmd = null;
if (definitionId != null) {
cmd = new GetDeploymentProcessDiagramCmd(definitionId);
}
if (instanceId != null) {
cmd = new ProcessInstanceDiagramCmd(instanceId);
}
if (taskId != null) {
Task task = engine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
cmd = new ProcessInstanceDiagramCmd(
task.getProcessInstanceId());
}
if (cmd != null) {
InputStream is = engine.getManagementService().executeCommand(cmd);
int len = 0;
byte[] b = new byte[1024];
while ((len = is.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}
}
示例:
<转载请注明来源: http://www.xdemo.org/spring-activiti-integration/ >