activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建

项目中需要整合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文件,解压后的目录打开如下:
    activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第1张图片
   

  3、打开上图中wars,可看到如下:
 activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第2张图片
   

   4、把上图中的api、editor、explorer、libs复制到项目的webapp下,如图:
 activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第3张图片

   5、进入第三步所示的WEB-INF的classes目录,可看到如图:
 activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第4张图片

   6、把上图中的editor.html、stencilset.json、plugins.xml复制到项目的src/main/sources中,(spring.xml是自己建立的)如图:
 activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第5张图片
  

 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
      
  


8、使用maven导入需要的pring、activiti以及mysql的jar包。Pom.xml内容如下:

  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
  


9、建立spring的配置文件spring.xml,如下:
  
  


      
    
      
	
	   
	   
	   
	    
	    
	
	
	
	   
	
	
	
        
		
	    
	    
	    
		
		
		
	
	
	
		
	


	
	
	
	
	
	
     
    
	
		
			
				text/html;charset=UTF-8
			
		
	


	
	
		
			
				
			
		
	
    
  


10、建立controller类,用来控制页面跳转到activiti-modeler流程设计页面:
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();
		}
	}
}


11、修改index.jsp为activiti.html:






Hello World!

activiti



12、启动项目,使用http://localhost:8080/activitiTest1访问项目,看到如下页面:

activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第6张图片
 
13、点击提交后,跳转到流程图设计界面:

activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建_第7张图片


参考文档: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

你可能感兴趣的:(json,数据库,java)