WFMC(工作流管理联盟):http://baike.baidu.com/view/2497858.htm
WFMS(工作流管理系统):http://baike.baidu.com/view/977667.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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<!-- Jar版本管理 -->
<
properties
>
<
springframework
>4.0.2.RELEASE</
springframework
>
<
hibernate
>4.3.4.Final</
hibernate
>
<
mysql.connector
>5.1.29</
mysql.connector
>
<
c3p0
>0.9.1.2</
c3p0
>
<
log4j
>1.2.17</
log4j
>
<
activiti
>5.15.1</
activiti
>
<
jstl
>1.2</
jstl
>
</
properties
>
<
dependencies
>
<!-- Spring web mvc -->
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-webmvc</
artifactId
>
<
version
>${springframework}</
version
>
</
dependency
>
<!-- Spring framework 4中的orm包已经单独拿出来了,所以要和hibernate集成,需要此包 -->
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-orm</
artifactId
>
<
version
>${springframework}</
version
>
</
dependency
>
<!-- 提供JMS,Freemarker,Quartz集成服务 -->
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-context-support</
artifactId
>
<
version
>${springframework}</
version
>
</
dependency
>
<!-- Hibernate -->
<
dependency
>
<
groupId
>org.hibernate</
groupId
>
<
artifactId
>hibernate-core</
artifactId
>
<
version
>${hibernate}</
version
>
</
dependency
>
<!-- MySQL驱动 -->
<
dependency
>
<
groupId
>mysql</
groupId
>
<
artifactId
>mysql-connector-java</
artifactId
>
<
version
>${mysql.connector}</
version
>
</
dependency
>
<!-- 连接池 -->
<
dependency
>
<
groupId
>c3p0</
groupId
>
<
artifactId
>c3p0</
artifactId
>
<
version
>${c3p0}</
version
>
</
dependency
>
<!-- log4j -->
<
dependency
>
<
groupId
>log4j</
groupId
>
<
artifactId
>log4j</
artifactId
>
<
version
>${log4j}</
version
>
</
dependency
>
<!-- jstl -->
<
dependency
>
<
groupId
>jstl</
groupId
>
<
artifactId
>jstl</
artifactId
>
<
version
>${jstl}</
version
>
</
dependency
>
<!-- activiti依赖 -->
<
dependency
>
<
groupId
>org.activiti</
groupId
>
<
artifactId
>activiti-engine</
artifactId
>
<
version
>${activiti}</
version
>
</
dependency
>
<!-- activiti 与 Spring 集成 -->
<
dependency
>
<
groupId
>org.activiti</
groupId
>
<
artifactId
>activiti-spring</
artifactId
>
<
version
>${activiti}</
version
>
</
dependency
>
<!-- junit -->
<
dependency
>
<
groupId
>junit</
groupId
>
<
artifactId
>junit</
artifactId
>
<
version
>3.8.1</
version
>
<
scope
>test</
scope
>
</
dependency
>
</
dependencies
>
|
与Spring集成:
activiti.cfg.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<
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"
>
<!-- Activiti处理引擎的配置,交由Spring管理 -->
<
bean
id
=
"processEngineConfiguration"
class
=
"org.activiti.spring.SpringProcessEngineConfiguration"
>
<!-- 配置数据源,和系统使用同一个数据源 -->
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"databaseSchemaUpdate"
value
=
"true"
/>
<
property
name
=
"jobExecutorActivate"
value
=
"false"
/>
<!-- 统一的事务管理 -->
<
property
name
=
"transactionManager"
ref
=
"transactionManager"
/>
<
property
name
=
"activityFontName"
value
=
"宋体"
/>
<
property
name
=
"labelFontName"
value
=
"宋体"
/>
</
bean
>
<
bean
id
=
"processEngine"
class
=
"org.activiti.spring.ProcessEngineFactoryBean"
>
<
property
name
=
"processEngineConfiguration"
ref
=
"processEngineConfiguration"
/>
</
bean
>
</
beans
>
|
activiti的API中,最终要的一个接口就是ProcessEngine,获取到ProcessEngine的实例,就获取了activiti体系中的所有api。重要的接口如下:
1
2
3
4
5
6
7
8
9
|
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代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
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<ProcessDefinition> 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<ProcessDefinition> 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<ProcessInstance> 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<ProcessInstance> 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<Task> 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<InputStream> 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/ >