activiti 第一篇:整合activiti 5.17.0 进项目

activiti 专栏收录该内容
1 篇文章 0 订阅

此篇是记录怎么整合activiti 5.17.0进项目

网络上有很多是整合5.17版本之前的,5.17版本与之前已经不一样的,经过两天的摸索,总算整合成功了。

下面就是整合的步骤,一共十二步:


一、下载activiti源代码(https://github.com/Activiti/Activiti/tree/activiti-5.17.0)

二、复制工程Activiti-activiti-5.17.0\modules\activiti-webapp-explorer2到workspace

三、导入工程activiti-webapp-explorer2,名称可以改成自己工程的名称,如:activiti-webapp

因为是maven项目,所以 导入之前先修改pom.xml,去掉不需要的配置,下面是我修改后的pom.xml

<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>com.activiti</groupId>
  <artifactId>activiti-webapp</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
      <activiti.version>5.17.0</activiti.version>
      <spring.version>4.0.8.RELEASE</spring.version>
      <jdk.version>1.7</jdk.version>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>    
    

    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-engine</artifactId>
      <version>${activiti.version}</version>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring</artifactId>
      <version>${activiti.version}</version>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-explorer</artifactId>
      <version>${activiti.version}</version>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-modeler</artifactId>
      <version>${activiti.version}</version>
      <exclusions>
        <exclusion>
          <groupId>xalan</groupId>
          <artifactId>xalan</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-diagram-rest</artifactId>
      <version>${activiti.version}</version>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-simple-workflow</artifactId>
      <version>${activiti.version}</version>
    </dependency>
              
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
<!--     <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>1.3.176</version>
    </dependency> -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.34</version>
    </dependency>
           
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>    

    
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </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-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>    
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.1</version>
    </dependency>
  </dependencies>


  <build>
    <finalName>activiti-webapp</finalName>
    <plugins>
        <!-- 编译  对应 周期的compile阶段-->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
          </configuration>
        </plugin>
        <!-- 布置到tomcat -->
        <plugin>
            <!-- 部署到eclipse内的tomcat,有以下三行配置就够了。如果要进行调试,

                   还需要配置工程右键->debug as->Debug configurations...->Maven build 在Goals填上tomcat7:run -->
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
        </plugin>    
    </plugins>
  </build>
 
</project>

四、删除不需要的文件,最后留下,如图:


注:蓝色圈是工程需要加入的。其他就是删除不需要的文件后留下的。

五、修改web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:j2ee="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3.0.xsd">
<!-- 
	这段代码不需要了,因为我们需要整合activiti的模型设计 
	<display-name>Vaadin Web Application</display-name>
    <distributable />
    
    
	<context-param>
		<description>Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>true</param-value>
	</context-param> -->

	<!-- To load the Spring context -->
	<listener>
		<listener-class>org.activiti.explorer.servlet.WebConfigurer</listener-class>
	</listener>

	<!-- To allow session-scoped beans in Spring -->
	<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>

 	<filter>
		<filter-name>UIFilter</filter-name>
		<filter-class>org.activiti.explorer.filter.ExplorerFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>UIFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping> 
  
    <filter>
        <filter-name>JSONPFilter</filter-name>
        <filter-class>org.activiti.explorer.servlet.JsonpCallbackFilter</filter-class>
    </filter>

  
    <filter-mapping>
        <filter-name>JSONPFilter</filter-name>
        <url-pattern>/service/*</url-pattern>
    </filter-mapping>

<!--这段代码不需要了,因为我们需要整合activiti的模型设计 
	<servlet>
		<servlet-name>Vaadin Application Servlet</servlet-name>
		<servlet-class>org.activiti.explorer.servlet.ExplorerApplicationServlet</servlet-class>
		<init-param>
			<param-name>widgetset</param-name>
			<param-value>org.activiti.explorer.CustomWidgetset</param-value>
		</init-param>
	</servlet>

	<servlet-mapping>
		<servlet-name>Vaadin Application Servlet</servlet-name>
		<url-pattern>/ui/*</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>Vaadin Application Servlet</servlet-name>
		<url-pattern>/VAADIN/*</url-pattern>
	</servlet-mapping> -->

	<!-- Session timeout on one day -->
	<session-config>
		<session-timeout>480</session-timeout>
	</session-config>
  


</web-app>

六、修改db.properties、根据自己使用的数据库进行配置。如果不修改默认使用H2内存数据库

七、修改org.activiti.explorer.conf.ApplicationConfiguration

注释或删除行

@ImportResource({"classpath:activiti-ui-context.xml", "classpath:activiti-login-context.xml", "classpath:activiti-custom-context.xml"})

package org.activiti.explorer.conf;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@PropertySources({
  @PropertySource(value = "classpath:db.properties", ignoreResourceNotFound = true),
  @PropertySource(value = "classpath:engine.properties", ignoreResourceNotFound = true)
})
@ComponentScan(basePackages = { "org.activiti.explorer.conf" })
//<span style="background-color: rgb(255, 255, 153);">@ImportResource({"classpath:activiti-ui-context.xml", "classpath:activiti-login-context.xml", "classpath:activiti-custom-context.xml"})</span>
public class ApplicationConfiguration {
  
}
八、修改org.activiti.explorer.servlet.WebConfigurer.initSpring()方法

  private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    //增加一行
    <span style="background-color: rgb(255, 255, 153);">dispatcherServlet.addMapping("/ui/*");</span>
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);
    
    return dispatcherServlet;
  }

九、增加模型的维护类com.flow.web.FlowModelController
package com.flow.web;

import java.io.InputStream;
import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.repository.Model;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Controller
public class FlowModelController {
	protected static final Logger LOGGER = LoggerFactory.getLogger(FlowModelController.class);

	@Autowired
	private RepositoryService repositoryService;
	
	/**
	 * 查询模型列表
	 * @return
	 */
	@RequestMapping("modelList")
	@ResponseBody
	public List<Model> modelList(){
		return repositoryService.createModelQuery().list();
	}
	
	/**
	 * 新建模型
	 * @return
	 */
	@RequestMapping("createModel")
	public String createFlow(){
		Authentication.setAuthenticatedUserId("kermit");
		String name = "请修改流程名称";
        List<Model> modelList = repositoryService.createModelQuery().modelName(name).list();
        
        Model model = null;
        if (modelList == null || modelList.isEmpty()) {
        
          model = repositoryService.newModel();
          model.setName(name);
          
          ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
          modelObjectNode.put("name", name);
          modelObjectNode.put("description", "请修改流程描述信息");
          model.setMetaInfo(modelObjectNode.toString());
          
          repositoryService.saveModel(model);
          
          //初始化模型数据
          try {
            InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/explorer/demo/model/test.svg");
            repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
          } catch(Exception e) {
            LOGGER.warn("Failed to read SVG", e);
          }
          
          try {
            InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/explorer/demo/model/test.model.json");
            repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
          } catch(Exception e) {
            LOGGER.warn("Failed to read editor JSON", e);
          }
        }else{
        	model = modelList.get(0);
        }
		return "redirect:/modeler.html?modelId=" +  model.getId();
	}
	
	/**
	 * 删除模型
	 * @param id
	 * @return
	 */
	@RequestMapping("removeModel")
	public String removeModel(String id){
		repositoryService.deleteModel(id);
		return "";
	}
}

十、维护界面index.html


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>activit dome</title>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" />

<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript">
	$.get("modelList",null,function(data){
		$('#modelList').datagrid('loadData',data);
	});
</script>
</head>
<body>
		<a href="createModel" class="easyui-linkbutton" data-options="iconCls:'icon-add'">Add Model</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',onClick:function(){
        	var row = $('#modelList').datagrid('getSelected');
        	$.get('removeModel',{id:row.id});
        	$('#modelList').datagrid('deleteRow',$('#modelList').datagrid('getRowIndex',row));
        }">remove Model</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',onClick:function(){
        	var row = $('#modelList').datagrid('getSelected');
        	if(row) window.location.href='modeler.html?modelId='+row.id;
        }">update Model</a>
    <table id="modelList" class="easyui-datagrid" title="MODEL LIST" style="width:700px;height:250px"
            data-options="singleSelect:true,collapsible:true,url:'',method:'get'">
        <thead>
            <tr>
                <th data-options="field:'id',width:80">ID</th>
                <th data-options="field:'name',width:100">NAME</th>
            </tr>
        </thead>
    </table>
</body>
</html>

这里用到easyui来展现,所以要导入easyui的js代码。

十一、修改org.activiti.explorer.servlet.DispatcherServletConfiguration

1.增加com.flow.web

@ComponentScan({"org.activiti.rest.editor", "org.activiti.rest.diagram",<span style="background-color: rgb(255, 255, 153);"> "com.flow.web"</span>})

2.增加重写方法addResourceHandlers(ResourceHandlerRegistry registry)

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
	    //配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理
	  registry.addResourceHandler("/js/**").addResourceLocations("/js/");
	  registry.addResourceHandler("/editor-app/**").addResourceLocations("/editor-app/");
	  registry.addResourceHandler("/diagram-viewer/**").addResourceLocations("/diagram-viewer/");
	  registry.addResourceHandler("/modeler.html").addResourceLocations("/");
	  registry.addResourceHandler("/index.html").addResourceLocations("/");
  }

十二、最后还要修改一个js,退出模型设计的时候,可以转到想去地址。

修改editor-app/configuration/toolbar-default-actions.js,两处分别是:

1.关闭模型编辑器跳转地址

        closeEditor: function(services) {
        	//window.location.href = "./";
        	window.location.href = "./index.html";
        },

2.保存并关闭模型编辑器跳转地址

    $scope.saveAndClose = function () {
    	$scope.save(function() {
    		//window.location.href = "./";
    		window.location.href = "./index.html";
    	});
    };



  • 0
    点赞
  • 0
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值