项目中需要整合activiti-modeler自定义流程,找了很多资料后,终于成功的跳转到activiti-modeler流程设计界面,以下是记录:
一、整合基础:eclipse4.4.1、tomcat7、jdk1.7、mysql5.6.25、maven3.2.5、activiti5.16.3、spring4.0.9
二、步骤:
1、下载activiti-5.16.3.zip: http://www.activiti.org/download.html
2、解压zip文件,解压后的目录打开如下:
4、把上图中的api、editor、explorer、libs复制到项目的webapp下,如图:
5、进入第三步所示的WEB-INF的classes目录,可看到如图:
6、把上图中的editor.html、stencilset.json、plugins.xml复制到项目的src/main/sources中,(spring.xml是自己建立的)如图:
7、配置web.xml文件,整个文件内容如下:
字符集过滤器
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
字符集编码
encoding
UTF-8
encodingFilter
/*
RestletServlet
org.restlet.ext.servlet.ServerServlet
org.restlet.application
org.activiti.rest.editor.application.ModelerRestApplication
RestletServlet
/service/*
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring.xml
springMVC
*.do
activiti.html
activiti.htm
activiti.jsp
default.html
default.htm
default.jsp
4.0.0
activitiTest1
activitiTest1
war
0.0.1-SNAPSHOT
activitiTest1 Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
org.springframework
spring-beans
4.0.9.RELEASE
org.springframework
spring-core
4.0.9.RELEASE
org.springframework
spring-aop
4.0.9.RELEASE
org.springframework
spring-context
4.0.9.RELEASE
org.springframework
spring-webmvc
4.0.9.RELEASE
org.springframework
spring-web
4.0.9.RELEASE
org.springframework
spring-aspects
4.0.9.RELEASE
org.springframework
spring-expression
4.0.9.RELEASE
org.springframework
spring-tx
4.0.9.RELEASE
javax.servlet
javax.servlet-api
3.1.0
com.fasterxml.jackson.core
jackson-annotations
2.2.3
com.fasterxml.jackson.core
jackson-core
2.2.3
com.fasterxml.jackson.core
jackson-databind
2.2.3
org.activiti
activiti-modeler
5.16
org.activiti
activiti-engine
5.16
org.activiti
activiti-explorer
5.16
org.activiti
activiti-rest
5.16
org.springframework
spring-context-support
4.0.9.RELEASE
mysql
mysql-connector-java
5.1.34
org.activiti
activiti-spring
5.16
org.springframework
spring-jdbc
4.0.9.RELEASE
activitiTest1
text/html;charset=UTF-8
package controllers;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Controller
public class ActivitiController {
@Autowired
private RepositoryService repositoryService;
/**
* 查询生日列表
*
* @param req
* @return
*/
@RequestMapping(value = "/activiti.do", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
@ResponseBody
public Object brithdayList(HttpServletRequest req) {
Map map = new HashMap();
map.put("name", "activiti");
return map;
}
@RequestMapping(value = "/create.do", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public void create(
@RequestParam("name") String name,
@RequestParam("key") String key,
@RequestParam(value = "description", required = false) String description,
HttpServletRequest request, HttpServletResponse response) {
try {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,
org.apache.commons.lang3.StringUtils
.defaultString(description));
Model newModel = repositoryService.newModel();
newModel.setMetaInfo(modelObjectNode.toString());
newModel.setName(name);
newModel.setKey(key);
repositoryService.saveModel(newModel);
ObjectNode editorNode = objectMapper.createObjectNode();
editorNode.put("id", "canvas");
editorNode.put("resourceId", "canvas");
ObjectNode stencilSetNode = objectMapper.createObjectNode();
stencilSetNode.put("namespace",
"http://b3mn.org/stencilset/bpmn2.0#");
editorNode.put("stencilset", stencilSetNode);
repositoryService.addModelEditorSource(newModel.getId(), editorNode
.toString().getBytes("utf-8"));
response.sendRedirect(request.getContextPath()
+ "/service/editor?id=" + newModel.getId());
} catch (Exception e) {
e.getStackTrace();
}
}
}
Hello World!
activiti
参考文档:http://weir2009.iteye.com/blog/2119072
http://lpyyn.iteye.com/blog/2149219
http://www.mossle.com/docs/activiti/index.html
http://blog.csdn.net/lfsf802/article/details/46237003
http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler.html