activiti自定义流程之整合(一):整体环境配置

时间:2024-04-19 16:06:02

结合之前所说的自定义流程的思路,分别是后台、前台、整合,之前的内容也分别进行了相关的练习和尝试,现在就该到了最后的整合了,依旧是以实现功能为目的,细节暂且不去管他。

因为我们实际项目后端用的是spring、spring mvc、mysql、mybatis,前台用的angular js,因此在整合时我也自己搭建使用了这样的环境。

1、 所使用的环境基础:eclipse4.4、mysql5.6、angularjs1.4、tomcat7、jdk1.7、maven3.2、spring4.0.9、activiit5.16、activiti-modeler5.16

2、 后端maven导包pom.xml文件如下:

  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>4.11</version>
  15. </dependency>
  16. <dependency>
  17. <groupId>org.springframework</groupId>
  18. <artifactId>spring-beans</artifactId>
  19. <version>4.0.9.RELEASE</version>
  20. </dependency>
  21. <dependency>
  22. <groupId>org.springframework</groupId>
  23. <artifactId>spring-core</artifactId>
  24. <version>4.0.9.RELEASE</version>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework</groupId>
  28. <artifactId>spring-aop</artifactId>
  29. <version>4.0.9.RELEASE</version>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.springframework</groupId>
  33. <artifactId>spring-context</artifactId>
  34. <version>4.0.9.RELEASE</version>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework</groupId>
  38. <artifactId>spring-webmvc</artifactId>
  39. <version>4.0.9.RELEASE</version>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.springframework</groupId>
  43. <artifactId>spring-web</artifactId>
  44. <version>4.0.9.RELEASE</version>
  45. </dependency>
  46. <dependency>
  47. <groupId>org.springframework</groupId>
  48. <artifactId>spring-aspects</artifactId>
  49. <version>4.0.9.RELEASE</version>
  50. </dependency>
  51. <dependency>
  52. <groupId>org.springframework</groupId>
  53. <artifactId>spring-expression</artifactId>
  54. <version>4.0.9.RELEASE</version>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.springframework</groupId>
  58. <artifactId>spring-tx</artifactId>
  59. <version>4.0.9.RELEASE</version>
  60. </dependency>
  61. <dependency>
  62. <groupId>javax.servlet</groupId>
  63. <artifactId>javax.servlet-api</artifactId>
  64. <version>3.1.0</version>
  65. </dependency>
  66. <dependency>
  67. <groupId>com.fasterxml.jackson.core</groupId>
  68. <artifactId>jackson-annotations</artifactId>
  69. <version>2.2.3</version>
  70. </dependency>
  71. <dependency>
  72. <groupId>com.fasterxml.jackson.core</groupId>
  73. <artifactId>jackson-core</artifactId>
  74. <version>2.2.3</version>
  75. </dependency>
  76. <dependency>
  77. <groupId>com.fasterxml.jackson.core</groupId>
  78. <artifactId>jackson-databind</artifactId>
  79. <version>2.2.3</version>
  80. </dependency>
  81. <dependency>
  82. <groupId>org.activiti</groupId>
  83. <artifactId>activiti-modeler</artifactId>
  84. <version>5.16</version>
  85. </dependency>
  86. <dependency>
  87. <groupId>org.activiti</groupId>
  88. <artifactId>activiti-engine</artifactId>
  89. <version>5.16</version>
  90. </dependency>
  91. <dependency>
  92. <groupId>org.activiti</groupId>
  93. <artifactId>activiti-explorer</artifactId>
  94. <version>5.16</version>
  95. </dependency>
  96. <dependency>
  97. <groupId>org.activiti</groupId>
  98. <artifactId>activiti-rest</artifactId>
  99. <version>5.16</version>
  100. </dependency>
  101. <dependency>
  102. <groupId>org.springframework</groupId>
  103. <artifactId>spring-context-support</artifactId>
  104. <version>4.0.9.RELEASE</version>
  105. </dependency>
  106. <dependency>
  107. <groupId>mysql</groupId>
  108. <artifactId>mysql-connector-<a href="http://lib.****.net/base/17" class="replace_word" title="Java EE知识库" target="_blank" style="color:#df3434; font-weight:bold;">java</a></artifactId>
  109. <version>5.1.34</version>
  110. </dependency>
  111. <dependency>
  112. <groupId>org.activiti</groupId>
  113. <artifactId>activiti-spring</artifactId>
  114. <version>5.16</version>
  115. </dependency>
  116. <dependency>
  117. <groupId>org.springframework</groupId>
  118. <artifactId>spring-jdbc</artifactId>
  119. <version>4.0.9.RELEASE</version>
  120. </dependency>
  121. <dependency>
  122. <groupId>org.springframework</groupId>
  123. <artifactId>spring-test</artifactId>
  124. <version>4.0.9.RELEASE</version>
  125. </dependency>
  126. <dependency>
  127. <groupId>org.activiti</groupId>
  128. <artifactId>activiti-bpmn-converter</artifactId>
  129. <version>5.16</version>
  130. </dependency>
  131. <dependency>
  132. <groupId>org.codehaus.jackson</groupId>
  133. <artifactId>jackson-core-asl</artifactId>
  134. <version>1.9.11</version>
  135. </dependency>
  136. <dependency>
  137. <groupId>org.codehaus.jackson</groupId>
  138. <artifactId>jackson-mapper-asl</artifactId>
  139. <version>1.9.11</version>
  140. </dependency>
  141. </dependencies>
  142. <build>
  143. <finalName>activitiTest1</finalName>
  144. </build>
  145. </project>

3、 web项目基础配置web.xml如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. lt;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. lt;/web-app>

4、 其他依赖环境,如下图中红线框起来的部分:其中包括使用angularjs依赖的js,整合activiti-modeler依赖的文件和使用ueditor插件所需的文件。(具体的文件可参考之前的博客内容)
activiti自定义流程之整合(一):整体环境配置

5、后台spring基础配置文件spring.xml如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. lt;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. <context:component-scan base-package="serviceImp" />
  17. <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  18. <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
  19. <property name="url" value="jdbc:mysql://127.0.0.1:3306/testtu?useUnicode=true&characterEncoding=utf8" ></property>
  20. <property name="username" value="root" ></property>
  21. <property name="password" value="123456" ></property>
  22. </bean>
  23. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  24. <property name="dataSource" ref="dataSource"></property>
  25. </bean>
  26. <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  27. <property name="dataSource" ref="dataSource" />
  28. <property name="databaseSchemaUpdate" value="true" />
  29. <property name="jobExecutorActivate" value="false"/>
  30. <property name="history" value="full"/>
  31. <property name="transactionManager" ref="transactionManager" />
  32. <!-- 配置事务管理器,统一事务 -->
  33. <!-- 设置建表策略,如果没有表,自动创建表 -->
  34. </bean>
  35. <!-- 创建流程引擎对象 -->
  36. <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  37. <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  38. </bean>
  39. <!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service -->
  40. <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  41. <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  42. <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  43. <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  44. <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
  45. <bean id="IdentityService" factory-bean="processEngine" factory-method="getIdentityService" />
  46. <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
  47. <bean id="mappingJacksonHttpMessageConverter"
  48. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  49. <property name="supportedMediaTypes">
  50. <list>
  51. <value>text/html;charset=utf-8</value>
  52. </list>
  53. </property>
  54. </bean>
  55. <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
  56. <bean
  57. class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  58. <property name="messageConverters">
  59. <list>
  60. <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
  61. </list>
  62. </property>
  63. </bean>
  64. lt;/beans>

5、 整个项目结构如图:

activiti自定义流程之整合(一):整体环境配置