此篇是记录怎么整合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
4.0.0
com.activiti
activiti-webapp
war
0.0.1-SNAPSHOT
5.17.0
4.0.8.RELEASE
1.7
junit
junit
4.11
test
javax.servlet
javax.servlet-api
3.1.0
provided
org.activiti
activiti-engine
${activiti.version}
org.activiti
activiti-spring
${activiti.version}
org.activiti
activiti-explorer
${activiti.version}
org.activiti
activiti-modeler
${activiti.version}
xalan
xalan
org.activiti
activiti-diagram-rest
${activiti.version}
org.activiti
activiti-simple-workflow
${activiti.version}
commons-dbcp
commons-dbcp
1.4
mysql
mysql-connector-java
5.1.34
commons-fileupload
commons-fileupload
1.3.1
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-core
${spring.version}
commons-logging
commons-logging
org.springframework
spring-context
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-orm
${spring.version}
org.aspectj
aspectjweaver
1.8.1
activiti-webapp
org.apache.maven.plugins
maven-compiler-plugin
2.3.2
${jdk.version}
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
五、修改web.xml
org.activiti.explorer.servlet.WebConfigurer
org.springframework.web.context.request.RequestContextListener
UIFilter
org.activiti.explorer.filter.ExplorerFilter
UIFilter
/*
JSONPFilter
org.activiti.explorer.servlet.JsonpCallbackFilter
JSONPFilter
/service/*
480
六、修改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" })
//@ImportResource({"classpath:activiti-ui-context.xml", "classpath:activiti-login-context.xml", "classpath:activiti-custom-context.xml"})
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/*");
//增加一行
dispatcherServlet.addMapping("/ui/*");
dispatcherServlet.setLoadOnStartup(1);
dispatcherServlet.setAsyncSupported(true);
return dispatcherServlet;
}
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 modelList(){
return repositoryService.createModelQuery().list();
}
/**
* 新建模型
* @return
*/
@RequestMapping("createModel")
public String createFlow(){
Authentication.setAuthenticatedUserId("kermit");
String name = "请修改流程名称";
List 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
activit dome
Add Model
remove Model
update Model
ID
NAME
十一、修改org.activiti.explorer.servlet.DispatcherServletConfiguration
1.增加com.flow.web
@ComponentScan({"org.activiti.rest.editor", "org.activiti.rest.diagram", "com.flow.web"})
@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";
},
$scope.saveAndClose = function () {
$scope.save(function() {
//window.location.href = "./";
window.location.href = "./index.html";
});
};