项目中须要整合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文件,解压后的文件夹打开例如以下:

    

3、打开上图中wars,可看到例如以下:

 

4、把上图中的api、editor、explorer、libs拷贝到项目的webapp下,如图:

 

5、进入第三步所看到的的WEB-INF的classes文件夹,可看到如图:

 

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border:none; max-width:100%">

6、把上图中的editor.html、stencilset.json、plugins.xml拷贝到项目的src/main/sources中,(spring.xml是自己建立的)如图:

 

7、配置web.xml文件,整个文件内容例如以下:

[html] view
plain
 copy

  1. <?

    xml version="1.0" encoding="UTF-8"?

    >

  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id="WebApp_ID" version="2.5">
  6. <filter>
  7. <description>字符集过滤器</description>
  8. <filter-name>encodingFilter</filter-name>
  9. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  10. <init-param>
  11. <description>字符集编码</description>
  12. <param-name>encoding</param-name>
  13. <param-value>UTF-8</param-value>
  14. </init-param>
  15. </filter>
  16. <filter-mapping>
  17. <filter-name>encodingFilter</filter-name>
  18. <url-pattern>/*</url-pattern>
  19. </filter-mapping>
  20. <servlet>
  21. <servlet-name>RestletServlet</servlet-name>
  22. <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
  23. <init-param>
  24. <param-name>org.restlet.application</param-name>
  25. <param-value>org.activiti.rest.editor.application.ModelerRestApplication</param-value>
  26. </init-param>
  27. </servlet>
  28. <servlet-mapping>
  29. <servlet-name>RestletServlet</servlet-name>
  30. <url-pattern>/service/*</url-pattern>
  31. </servlet-mapping>
  32. <servlet>
  33. <servlet-name>springMVC</servlet-name>
  34. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  35. <init-param>
  36. <param-name>contextConfigLocation</param-name>
  37. <param-value>classpath:spring.xml</param-value>
  38. </init-param>
  39. </servlet>
  40. <servlet-mapping>
  41. <servlet-name>springMVC</servlet-name>
  42. <url-pattern>*.do</url-pattern>
  43. </servlet-mapping>
  44. <welcome-file-list>
  45. <welcome-file>activiti.html</welcome-file>
  46. <welcome-file>activiti.htm</welcome-file>
  47. <welcome-file>activiti.jsp</welcome-file>
  48. <welcome-file>default.html</welcome-file>
  49. <welcome-file>default.htm</welcome-file>
  50. <welcome-file>default.jsp</welcome-file>
  51. </welcome-file-list>
  52. </web-app>

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

[plain] view
plain
 copy

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>activitiTest1</groupId>
  5. <artifactId>activitiTest1</artifactId>
  6. <packaging>war</packaging>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <name>activitiTest1 Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10. <dependencies>
  11. <dependency>
  12. <groupId>junit</groupId>
  13. <artifactId>junit</artifactId>
  14. <version>3.8.1</version>
  15. <scope>test</scope>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework</groupId>
  19. <artifactId>spring-beans</artifactId>
  20. <version>4.0.9.RELEASE</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.springframework</groupId>
  24. <artifactId>spring-core</artifactId>
  25. <version>4.0.9.RELEASE</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework</groupId>
  29. <artifactId>spring-aop</artifactId>
  30. <version>4.0.9.RELEASE</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework</groupId>
  34. <artifactId>spring-context</artifactId>
  35. <version>4.0.9.RELEASE</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework</groupId>
  39. <artifactId>spring-webmvc</artifactId>
  40. <version>4.0.9.RELEASE</version>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework</groupId>
  44. <artifactId>spring-web</artifactId>
  45. <version>4.0.9.RELEASE</version>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.springframework</groupId>
  49. <artifactId>spring-aspects</artifactId>
  50. <version>4.0.9.RELEASE</version>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.springframework</groupId>
  54. <artifactId>spring-expression</artifactId>
  55. <version>4.0.9.RELEASE</version>
  56. </dependency>
  57. <dependency>
  58. <groupId>org.springframework</groupId>
  59. <artifactId>spring-tx</artifactId>
  60. <version>4.0.9.RELEASE</version>
  61. </dependency>
  62. <dependency>
  63. <groupId>javax.servlet</groupId>
  64. <artifactId>javax.servlet-api</artifactId>
  65. <version>3.1.0</version>
  66. </dependency>
  67. <dependency>
  68. <groupId>com.fasterxml.jackson.core</groupId>
  69. <artifactId>jackson-annotations</artifactId>
  70. <version>2.2.3</version>
  71. </dependency>
  72. <dependency>
  73. <groupId>com.fasterxml.jackson.core</groupId>
  74. <artifactId>jackson-core</artifactId>
  75. <version>2.2.3</version>
  76. </dependency>
  77. <dependency>
  78. <groupId>com.fasterxml.jackson.core</groupId>
  79. <artifactId>jackson-databind</artifactId>
  80. <version>2.2.3</version>
  81. </dependency>
  82. <dependency>
  83. <groupId>org.activiti</groupId>
  84. <artifactId>activiti-modeler</artifactId>
  85. <version>5.16</version>
  86. </dependency>
  87. <dependency>
  88. <groupId>org.activiti</groupId>
  89. <artifactId>activiti-engine</artifactId>
  90. <version>5.16</version>
  91. </dependency>
  92. <dependency>
  93. <groupId>org.activiti</groupId>
  94. <artifactId>activiti-explorer</artifactId>
  95. <version>5.16</version>
  96. </dependency>
  97. <dependency>
  98. <groupId>org.activiti</groupId>
  99. <artifactId>activiti-rest</artifactId>
  100. <version>5.16</version>
  101. </dependency>
  102. <dependency>
  103. <groupId>org.springframework</groupId>
  104. <artifactId>spring-context-support</artifactId>
  105. <version>4.0.9.RELEASE</version>
  106. </dependency>
  107. <dependency>
  108. <groupId>mysql</groupId>
  109. <artifactId>mysql-connector-java</artifactId>
  110. <version>5.1.34</version>
  111. </dependency>
  112. <dependency>
  113. <groupId>org.activiti</groupId>
  114. <artifactId>activiti-spring</artifactId>
  115. <version>5.16</version>
  116. </dependency>
  117. <dependency>
  118. <groupId>org.springframework</groupId>
  119. <artifactId>spring-jdbc</artifactId>
  120. <version>4.0.9.RELEASE</version>
  121. </dependency>
  122. </dependencies>
  123. <build>
  124. <finalName>activitiTest1</finalName>
  125. </build>
  126. </project>

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

[html] view
plain
 copy

  1. <?

    xml version="1.0" encoding="UTF-8"?

    >

  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  11. http://www.springframework.org/schema/mvc
  12. http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  13. <context:annotation-config />
  14. <mvc:annotation-driven />
  15. <context:component-scan base-package="controllers" />
  16. <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  17. <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
  18. <property name="url" value="jdbc:mysql://192.168.0.201:3306/testtu?

    useUnicode=true&characterEncoding=utf8" ></property>

  19. <property name="username" value="root" ></property>
  20. <property name="password" value="123456" ></property>
  21. </bean>
  22. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  23. <property name="dataSource" ref="dataSource"></property>
  24. </bean>
  25. <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  26. <property name="dataSource" ref="dataSource" />
  27. <property name="databaseSchemaUpdate" value="true" />
  28. <property name="jobExecutorActivate" value="false"/>
  29. <property name="history" value="full"/>
  30. <property name="transactionManager" ref="transactionManager" />
  31. <!-- 配置事务管理器。统一事务 -->
  32. <!-- 设置建表策略,假设没有表,自己主动创建表 -->
  33. </bean>
  34. <!-- 创建流程引擎对象 -->
  35. <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  36. <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  37. </bean>
  38. <!-- 由流程引擎对象。提供的方法,创建项目中使用的Activiti工作流的Service -->
  39. <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  40. <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  41. <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  42. <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  43. <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
  44. <!-- 避免IE运行AJAX时,返回JSON出现下载文件 -->
  45. <bean id="mappingJacksonHttpMessageConverter"
  46. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  47. <property name="supportedMediaTypes">
  48. <list>
  49. <value>text/html;charset=UTF-8</value>
  50. </list>
  51. </property>
  52. </bean>
  53. <!-- 启动Spring MVC的注解功能,完毕请求和注解POJO的映射 -->
  54. <bean
  55. class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  56. <property name="messageConverters">
  57. <list>
  58. <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
  59. </list>
  60. </property>
  61. </bean>
  62. </beans>

10、建立controller类。用来控制页面跳转到activiti-modeler流程设计页面:

[java] view
plain
 copy

  1. package controllers;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.activiti.editor.constants.ModelDataJsonConstants;
  7. import org.activiti.engine.RepositoryService;
  8. import org.activiti.engine.repository.Model;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import com.fasterxml.jackson.databind.ObjectMapper;
  16. import com.fasterxml.jackson.databind.node.ObjectNode;
  17. @Controller
  18. public class ActivitiController {
  19. @Autowired
  20. private RepositoryService repositoryService;
  21. /**
  22. * 查询生日列表
  23. *
  24. * @param req
  25. * @return
  26. */
  27. @RequestMapping(value = "/activiti.do", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
  28. @ResponseBody
  29. public Object brithdayList(HttpServletRequest req) {
  30. Map<String, Object> map = new HashMap<String, Object>();
  31. map.put("name", "activiti");
  32. return map;
  33. }
  34. @RequestMapping(value = "/create.do", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
  35. public void create(
  36. @RequestParam("name") String name,
  37. @RequestParam("key") String key,
  38. @RequestParam(value = "description", required = false) String description,
  39. HttpServletRequest request, HttpServletResponse response) {
  40. try {
  41. ObjectMapper objectMapper = new ObjectMapper();
  42. ObjectNode modelObjectNode = objectMapper.createObjectNode();
  43. modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
  44. modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
  45. modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,
  46. org.apache.commons.lang3.StringUtils
  47. .defaultString(description));
  48. Model newModel = repositoryService.newModel();
  49. newModel.setMetaInfo(modelObjectNode.toString());
  50. newModel.setName(name);
  51. newModel.setKey(key);
  52. repositoryService.saveModel(newModel);
  53. ObjectNode editorNode = objectMapper.createObjectNode();
  54. editorNode.put("id", "canvas");
  55. editorNode.put("resourceId", "canvas");
  56. ObjectNode stencilSetNode = objectMapper.createObjectNode();
  57. stencilSetNode.put("namespace",
  58. "http://b3mn.org/stencilset/bpmn2.0#");
  59. editorNode.put("stencilset", stencilSetNode);
  60. repositoryService.addModelEditorSource(newModel.getId(), editorNode
  61. .toString().getBytes("utf-8"));
  62. response.sendRedirect(request.getContextPath()
  63. + "/service/editor?id=" + newModel.getId());
  64. } catch (Exception e) {
  65. e.getStackTrace();
  66. }
  67. }
  68. }

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

[html] view
plain
 copy

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. </head>
  6. <body>
  7. <h2>Hello World!</h2>
  8. <a href="./activiti.do">activiti</a>
  9. <form action="./create.do" method="get">
  10. <input type="text" id="name" name="name"></input>
  11. <input type="text" id="key" name="key"></input>
  12. <input type="text" id="description" name="description"></input>
  13. <input type="submit" value="提交">
  14. </form>
  15. </body>
  16. </html>

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



 

13、点击提交后,跳转到流程图设计界面:

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

activiti自己定义流程之Spring整合activiti-modeler实例(一):环境搭建的更多相关文章

  1. activiti自己定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义

    注:(1)环境搭建:activiti自己定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建         (2)创建流程模型:activiti自己定义流程之Spr ...

  2. activiti自己定义流程之Spring整合activiti-modeler实例(七):任务列表展示

    1.通过上一节的操作,能够知道流程启动以后会同一时候生成一个流程实例和用户任务.这个用户任务保存在act_ru_task和act_hi_task表中,从表明能够看出ru是runtime,hi是hist ...

  3. activiti自己定义流程之Spring整合activiti-modeler实例(六):启动流程

    1.启动流程并分配任务是单个流程的正式開始,因此要使用到runtimeService接口.以及相关的启动流程的方法.我习惯于用流程定义的key启动,由于有多个版本号的流程定义时,用key启动默认会使用 ...

  4. activiti自定义流程之Spring整合activiti-modeler5.16实例(五):流程定义列表

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

  5. activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义

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

  6. activiti自定义流程之Spring整合activiti-modeler5.16实例(九):历史任务查询

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

  7. activiti自定义流程之Spring整合activiti-modeler5.16实例(八):完成个人任务

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

  8. activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示

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

  9. activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程

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

随机推荐

  1. (算法)位图BitMap

    题目: 给定一数组,大小为M,数组中的数字范围为1-N,如果某带宽有限,无法传输该大小的数组,该怎么办? 思路: 通过位图BitMap来压缩数组,将数组中每个数字在bit位上标志,这样就可以将数组大小 ...

  2. 运行top时,会报unknown terminal type错误

    问题: 在板子上执行top时总是提示'vt102': unknown terminal type. 执行了export TERM=xterm,还是不管用 解决: 执行export,方向没有设置TERM ...

  3. php之快速入门学习-17(PHP 命名空间)

    PHP 命名空间(namespace) PHP 命名空间(namespace)是在PHP 5.3中加入的,如果你学过C#和Java,那命名空间就不算什么新事物. 不过在PHP当中还是有着相当重要的意义 ...

  4. Windows下安装配置SBT

    1:安装包下载界面 http://www.scala-sbt.org/download.html 下载后进行安装. 安装路径:D:\Java\sbt\conf 2:进行配置 (1)sbtconfig. ...

  5. The jQuery HTML5 Audio / Video Library (jQuery jPlayer插件给你的站点增加视频和音频功能)

    http://jplayer.org/ The jQuery HTML5 Audio / Video Library jPlayer is the completely free and open s ...

  6. Linux网卡高级命令

    网卡的高级命令 [root@gechong ~]# mii-tool No interface specified usage: mii-tool [-VvRrwl] [-A media,... | ...

  7. margin 负边距应用

    margin-right:负值,在没有设置DOM元素宽度的前提下,DOM元素宽度变宽. <!DOCTYPE html> <html lang="zh-CN"> ...

  8. jQuery中first-child与first选择器区别

    1.first-child first-child为每个父级元素匹配第一个子元素,可以匹配出多个元素: 示例代码: <!DOCTYPE html> <html lang=" ...

  9. EXCEPTION-STRUTS2

      CreateTime--2016年8月29日17:05:50Author:Marydon 声明:异常类文章主要是记录了我遇到的异常信息及解决方案,解决方案大部分都是百度解决的,(这里只是针对我遇到 ...

  10. 【laravel5.4】使用baum\node 类库实现无限极分类

    1.在model中引入baum\node 类库,并继承,具体参考 https://packagist.org/packages/baum/baum 2.核心代码: /* * model::create ...