Activiti moduler + spring web环境构建(二)
项目结构:基于activiti 5.21版本,可下载附件demo项目
maven 配置:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.activiti.examples</groupId> <artifactId>activiti-examples</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>BPMN 2.0 with Activiti - Examples</name> <properties> <activiti-version>5.21.0</activiti-version> <spring-version>4.3.3.RELEASE</spring-version> </properties> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${activiti-version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-modeler</artifactId> <exclusions> <exclusion> <groupId>xalan</groupId> <artifactId>xalan</artifactId> </exclusion> </exclusions> <version>${activiti-version}</version> </dependency> <!-- 查看流程详细定义 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-diagram-rest</artifactId> <version>${activiti-version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-explorer</artifactId> <exclusions> <exclusion> <artifactId>vaadin</artifactId> <groupId>com.vaadin</groupId> </exclusion> <exclusion> <artifactId>dcharts-widget</artifactId> <groupId>org.vaadin.addons</groupId> </exclusion> <exclusion> <artifactId>activiti-simple-workflow</artifactId> <groupId>org.activiti</groupId> </exclusion> </exclusions> <version>${activiti-version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${activiti-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.39</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.7.6</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <inherited>true</inherited> <configuration> <classpathContainers> <classpathContainer>org.eclipse.jdt.USER_LIBRARY/Activiti Designer Extensions</classpathContainer> </classpathContainers> </configuration> </plugin> </plugins> </build> </project>
web配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <distributable /> <!-- To load the Spring context --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 编码过滤器 放在filter的第一位最佳--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--springMVC配置,该servlet会拦截所有匹配的URL请求--> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- Session timeout on one day --> <session-config> <session-timeout>480</session-timeout> </session-config> </web-app>
spring基础配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:db.properties" file-encoding="utf-8" ignore-unresolvable="true"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="defaultAutoCommit" value="false"/> </bean> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="dataSource" ref="dataSource"/> <property name="databaseType" value="${db}"/> <property name="databaseSchemaUpdate" value="true"/> <property name="jobExecutorActivate" value="false"/> <!--<property name="enableDatabaseEventLogging" value="true" /> <property name="customFormTypes"> <list> <bean class="org.activiti.explorer.form.UserFormType"/> <bean class="org.activiti.explorer.form.ProcessDefinitionFormType"/> <bean class="org.activiti.explorer.form.MonthFormType"/> </list> </property>--> </bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration"/> </bean> <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/> <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/> <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/> <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/> <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" /> <bean id="formService" factory-bean="processEngine" factory-method="getFormService" /> <!-- json处理,这里不可改成其他类,有依赖关系 --> <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"></bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> </beans>
spring MVC配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <!--配置扫描controller包,注册pojo (org.activiti.rest.editor,org.activiti.rest.diagram)--> <context:component-scan base-package="com.bpm.controller,org.activiti.rest.editor"></context:component-scan> <!--使用注解的方式--> <mvc:annotation-driven/> <!-- 避免IE执行AJAX时,返回JSON出现下载文件 --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter"/><!-- json转换器 --> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"></property> </bean> <!-- 资源访问处理器 --> <mvc:resources mapping="/resources/**" location="/resources/" /> </beans>
基础操作
@RequestMapping(value = "/create", method = RequestMethod.POST, produces = "application/json;charset=utf-8") public String create(HttpServletRequest request, HttpServletResponse response) { String id = ""; try { String name = request.getParameter("name"), key = request.getParameter("key"), description = request.getParameter("category"); // 元数据信息 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); newModel.setCategory(description); repositoryService.saveModel(newModel); // 创建所必须的JSON数据 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")); id = newModel.getId(); } catch (Exception e) { e.printStackTrace(); } return "redirect:/demo/editor?modelId=" + id; } @RequestMapping("/deploy/{modelId}") @ResponseBody public Result deploy(@PathVariable String modelId) throws IOException { Result result = new Result(); try { // 将创建的模型转为json JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelId)); BpmnJsonConverter jsonConverter = new BpmnJsonConverter(); BpmnModel modelCt = jsonConverter.convertToBpmnModel(editorNode); // 获取流程模型 Model model = repositoryService.createModelQuery().modelId(modelId).singleResult(); // 发布流程模型 String processName = model.getName() + ".bpmn20.xml"; repositoryService.createDeployment().name(model.getName()).addBpmnModel(processName, modelCt).deploy(); } catch (Exception e) { e.printStackTrace(); result.setSuccess(false); result.setMsg(e.getMessage()); } return result; } @RequestMapping("/process/start/{processDefinitionId}") @ResponseBody public Map<String, Object> startProcess(@PathVariable String processDefinitionId, ModelMap mav, HttpServletRequest request, HttpServletResponse response) throws IOException { Map<String, Object> result = new HashMap<String, Object>(); result.put("success", true); try { Object obj = request.getSession().getAttribute("user"); // 查询是否有表单,有的话弹出表单,否则的话直接提交任务 FormDataImpl formData = (FormDataImpl) formService.getStartFormData(processDefinitionId); List<FormProperty> propertyList = formData.getFormProperties(); result.put("hasForm", propertyList.isEmpty() ? false : true); if (propertyList.isEmpty()) { // 定义map用于往工作流数据库中传值。 Map variables = new HashMap(); variables.put("applyUserName", ((User) obj).getFirstName()); identityService.setAuthenticatedUserId(((User) obj).getId()); // 启动实例 runtimeService.startProcessInstanceById(processDefinitionId, variables); } } catch (Exception e) { e.printStackTrace(); result.put("success", false); result.put("msg", e.getMessage()); } return result; } /** * 获取表单用于展示 * * @param type start 表示启动时的表单;task 表示任务中的表单 * @param id 类型为start时,为流程定义ID;类型为task时,为任务ID * @param modelMap 返回前台数据 * @return String 页面 * @author DS */ @RequestMapping(value = "/process/getForm/{type}/{id}") public String getForm(@PathVariable String type, @PathVariable String id, ModelMap modelMap) { FormDataImpl formData = null; if ("start".equals(type)) { formData = (FormDataImpl) formService.getStartFormData(id); } else if ("task".equals(type)) { formData = (FormDataImpl) formService.getTaskFormData(id); } // 获取属性设置 List<FormProperty> formProperties = formData.getFormProperties(); Object values; Map<String,Object> attributes = new HashMap<String, Object>(); for (FormProperty formProperty : formProperties) { if("date".equals(formProperty.getType().getName()) || "enum".equals(formProperty.getType().getName())){ values = formProperty.getType().getInformation("values"); if (values != null) { attributes.put(formProperty.getId(), values); }else { values = formProperty.getType().getInformation("datePattern"); if (values != null){ attributes.put(formProperty.getId(),values); } } } } modelMap.put("attributes",attributes); modelMap.put("formList", formProperties); modelMap.put("type",type); modelMap.put("id",id); return "apply"; } /** * 保存表单数据 * * @param type start 表示启动时的表单;task 表示任务中的表单 * @param id 类型为start时,为流程定义ID;类型为task时,为任务ID * @param request 请求 * @param response 响应 * @return Result 保存结果 * @author DS */ @RequestMapping(value = "/process/saveForm/{type}/{id}") @ResponseBody public Result submitStartFormAndStartProcessInstance(@PathVariable String type, @PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) throws IOException { Result result = new Result(); Map<String, String> formProperties = new HashMap<String, String>(); // 从request中读取参数然后转换 Map<String, String[]> parameterMap = request.getParameterMap(); Set<String> keySet = parameterMap.keySet(); for (String key : keySet) { formProperties.put(key, parameterMap.get(key)[0]); } // 用户未登录不能操作,实际应用使用权限框架实现,例如Spring Security、Shiro等 Object obj = request.getSession().getAttribute("user"); try { if("start".equals(type)){ formProperties.put("applyUserName",((User)obj).getFirstName()); formProperties.put("applyUserId",((User)obj).getId()); identityService.setAuthenticatedUserId(((User)obj).getId()); ProcessInstance processInstance = formService.submitStartFormData(id, formProperties); logger.debug("流程启动成功: {}", processInstance.getId()); }else if ("task".equals(type)){ formService.submitTaskFormData(id,formProperties); logger.debug("流程进入下一步"); } }catch (Exception e){ result.setSuccess(false); result.setMsg(e.getMessage()); e.printStackTrace(); }finally { identityService.setAuthenticatedUserId(null); } result.setResult(id); return result; }
相关推荐
这个实例项目是基于Activiti 5.21版本构建的,它结合了moduler模块化管理和Spring MVC框架,提供了完整的Web应用解决方案。让我们深入探讨一下这个项目中的主要知识点。 1. **Activiti工作流引擎**: - Activiti ...
本项目是关于"activiti+spring+spring Mvc+mybatis+maven"的整合,旨在创建一个基于Activiti工作流引擎、Spring、Spring MVC、MyBatis以及Maven的开发环境。下面将详细介绍这些技术及其整合过程。 首先,`activiti`...
springboot2+vue2+activiti7+myflow(vue下public目录下 window.open打开)工作流设计请假实战例子。。
用springboot2来集成的activiti6,里面包括了activiti的在线web设计器,高亮显示当前流程实例的正在执行的任务,对activiti任务的测试 上面的功能都是在一个项目中,且项目中有详细的注释,也有一个项目说明.txt用于...
这个压缩包文件的标题表明它是一个基于Activiti工作流引擎和Spring MVC框架构建的基础Web项目。 Activiti是一款流行的开源工作流管理系统,用于实现业务流程自动化。而Spring MVC是Spring框架的一个模块,专门用于...
标题中的“activiti+spring mvc+maven+extjs mvc+mybatis”是一个集成的IT解决方案,用于构建一个简单的请假工作流程应用。这个项目利用了多种技术来创建一个前端和后端无缝协作的系统。 1. **Activiti**:Activiti...
(一)首先 pom.xml 文件中引入相关的依赖 ...(二)springboot 的配置文件 application.yml中添加相关的配置 (三)流程资源 (四)编写Applocation主程序 (五)编写基于SpringBootTest的测试程序
框架整合Spring MVC3.23+Spring3.23+Hibernate4.2.3+Activiti5.16.3,三层架构dao,service,controller,使用proxool连接池(已配置好监听器),默认链接mysql数据库。可根据项目开发需要,做适当修改,各项配置齐全...
activiti中有四种网关:并行网关,排他网关,包含网关,基于事件网关 排它网关: 内部是一个“X”图标,用来在流程中实现决策。 当流程执行到这个网关,所有外出顺序流都会被处理一遍。 其中条件解析为true的顺序...
当我们将 `Activiti` 与 `Spring` 结合使用时,可以构建出高效、灵活且易于维护的业务流程管理系统。 `JUnit` 是一个广泛使用的Java单元测试框架,它使得开发者能够编写和运行可重复的自动化测试用例,以确保代码的...
这是一个基于Spring Boot、Activiti、Shiro和Layui的权限管理系统源码,结合了MySQL数据库,用于实现高效、安全的后台管理功能。下面将详细解释这套系统的各个组成部分及其核心知识点。 1. **Spring Boot**: Spring...
在本项目"activiti+springMVC+mybatis rest风格整合demo"中,开发者通过集成Activiti、Spring MVC和MyBatis三个核心组件,构建了一个基于RESTful API的工作流管理系统。这个项目对于初学者来说是一个很好的学习资源...
标题中的“springboot+activiti+vue+thymleaf 版本”指的是一个基于Spring Boot、Activiti、Vue.js和Thymeleaf的综合工作流管理系统。这个系统结合了四个关键的技术栈,构建了一个功能丰富的业务流程自动化平台。 1...
在本项目中,我们主要探讨的是如何将Java与Spring Boot框架相结合,利用JWT(JSON Web Token)和Spring Security来构建一个安全的Web应用程序。这个实战项目涵盖了从基础概念到实际应用的完整流程,旨在帮助开发者...
这个案例涵盖了用户登录、流程启动、任务查询、任务处理、流程图展示等功能,通过实践,你可以了解到如何在真实环境中部署和运行Activiti流程,以及如何处理复杂的业务逻辑。 此外,"activiti.xlsx"是一份详细的...
Spring MVC是Spring框架的一个模块,专门用于构建Web应用程序。它提供了模型-视图-控制器(MVC)架构模式,使得开发人员能够将业务逻辑、数据处理和用户界面分离。4.0.6版本是在Spring 4.x系列的一个稳定版本,支持...
### 二、Spring框架 **Spring** 是一个开源的轻量级Java EE应用开发框架,它的目标是简化企业级应用的开发过程。Spring框架提供了一个全面的编程模型,支持多种服务层组件。 #### Spring框架的主要特性包括: - **...
集成activiti moduler5.22官方流程设计器的springboot工程。自行修改yml配置文件中的数据库地址。启动后先访问 地址:端口/activiti/model获得model的id,再访问 地址:端口/modeler.html?modelId=xx,将xx改为获得...
这个压缩包包含了两个关键组件:`Activiti-develop.zip` 和 `Activiti+V5.21+用户手册+中文版.pdf`。 首先,`Activiti-develop.zip` 文件很可能是Activiti的源代码,这对于开发者来说是一份宝贵的资源。Activiti是...