文章作者:竹子CN
文章地址:https://blog.csdn.net/u010411264/article/details/71480354
参考大佬的这篇博文可以跑起来o( ̄︶ ̄)o
这编文章主要目的是:Activiti Modeler5.22.0整合到Spring项目。
Activiti Modeler 离不开spring,因此我们需要创建一个简单的spring项目。这个项目的名为:bamboo-activiti,bamboo-activiti项目简单实现了springmvc跳转的hello world界面。
bamboo-activiti下面下载如下。
:http://pan.baidu.com/s/1pL8st4Z
Spring版本:4.15(因为在Activiti 5.22.0中用到4.15版本,所以也选择此版本)
Spring默认配置文件applicationMVC.xml:applicationContext.xml(在此配置文件中,我们配置数据源和事务处理器和导入SpringMVC配置文件)
配置applicationMVC.xml:此配置文件主要配置SpringMVC的扫描注解和页面去向
整合需要的资源如下:
1.官方下载Activiti 源代码: https://github.com/Activiti/Activiti ,云盘下载:http://pan.baidu.com/s/1geVZaoz,如下:
2.下载Activiti 5.22.0:http://pan.baidu.com/s/1eRWHaBw (我已经下载好了的)。官网下载地址:https://www.activiti.org/
1、解压Activiti-master.zip,找到modules\activiti-webapp-explorer2\src\main\webapp下的diagram-viewer、editor-app、modeler.html,将其加到bamboo-activiti项目的webapp中。(这一步主要是Activiti Modeler的前段页面)
2、解压activiti-5.22.0.zip,找到wars在的activiti-explorer.war,将其放在tomcat的webapps下,启动tomcat将其解压,找activiti-explorer\WEB-INF\lib,拷贝所有jar包到bamboo-activiti的lib下。
3、给Activiti Modeler做配置文件applicationActiviti.xml:在并bamboo-activiti项目中添加名为,applicationActiviti.xml的配置文件,并在applicationContext.xml中引入import,
在Activiti-master中找到stencilset.json文件加到bamboo-activiti项目的配置文件里面。
applicationActiviti.xml的主要配置如下:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="dataSource" />
bean>
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="databaseType" value="mysql" />
<property name="activityFontName" value="SimSun">property>
<property name="labelFontName" value="SimSun">property>
<property name="history" value="full">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"/>
4、在Activiti 5.22.0的libs中找到activiti-modeler-5.22.0-sources.jar,将其解压,可以看到如下:
在bamboo-activiti项目中创建包名为:com.rest.editor,将上图3个类加到其中,如下图示:
回看第3步applicationActiviti.xml配置所指向的路径就是这3个类,这3个类就是Activiti Modeler的后台配置类。
5、在editor-app中找到app-cfg.js文件,将’contextRoot’ : ‘/activiti-explorer/service’,修改为本项目的路径。如下:
6,编写Activiti Modeler 页面跳转代码,如下:
/**
* 创建模型
*/
@RequestMapping("create")
public void create(HttpServletRequest request, HttpServletResponse response) {
try {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ObjectMapper objectMapper = new ObjectMapper();
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);
Model modelData = repositoryService.newModel();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, "hello1111");
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
String description = "hello1111";
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName("hello1111");
modelData.setKey("12313123");
//保存模型
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());
} catch (Exception e) {
System.out.println("创建模型失败:");
}
}
7,修改index.jsp,添加链接
activiti-modele-index
注意:右键属性,将下图:
改
8、别忘了Activiti 5.22.0数据库,在Activiti 5.22.0.zip中。
1)整合中文版下载:http://pan.baidu.com/s/1miHRTPY
下载地址:http://pan.baidu.com/s/1miHlZBy
在实际的配置中前端的json如果没有解析显示菜单的话,配置js这个地方
配置1:
版权声明:竹子原创,未经允许不得转载