目标:若依整合activiti6
好的,上边4篇,算是基础环境的准备,这篇开始终于进入了主题,开始整合activiti。
一、首先在根目录pom文件中声明activiti依赖,但是要移除activiti中的mybatis依赖,因为已经升级成mybatis-plus了,不清楚的往前翻一翻了解一下来龙去脉。
二、application.yml,添加如下配置,注意这是要配在spring下一层的
三、创建ruoyi-activiti模块
1、层级和包的情况如图
2、activiti模块的pom,引入这两个依赖
3、根目录pom,声明activiti模块,因为其他模块也是做么做的,咱别特立独行
4、admin模块的pom,引入activiti依赖
5、修改RuoYiApplication.java文件
6、运行项目,如果提示act_**表不存在的话,在application-druid.yml里url参数后边拼上nullCatalogMeansCurrent=true,我的是这样的
url: jdbc:mysql://localhost:3306/ry_mp_activiti?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
7、项目运行起来不报错,数据库里会多出28张act开头的表
四、下面加点代码试试,看能不能正常用
1、在activiti模块的config包里创建ActivitiConfig.java,这是为了注入activiti的api
package com.ruoyi.act.config;
import org.activiti.engine.*;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
/**
* @author badcat
* @date 2021-08-23 0:22
*/
@Configuration
public class ActivitiConfig {
@Autowired
private DataSource dataSource;
@Autowired
private PlatformTransactionManager platformTransactionManager;
private SpringProcessEngineConfiguration springProcessEngineConfiguration(){
SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration();
spec.setDataSource(dataSource);
spec.setTransactionManager(platformTransactionManager);
spec.setDatabaseSchemaUpdate("true");
return spec;
}
private ProcessEngineFactoryBean processEngine(){
ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
processEngineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration());
return processEngineFactoryBean;
}
@Bean
public RepositoryService repositoryService() throws Exception{
return processEngine().getObject().getRepositoryService();
}
@Bean
public RuntimeService runtimeService() throws Exception{
return processEngine().getObject().getRuntimeService();
}
@Bean
public TaskService taskService() throws Exception{
return processEngine().getObject().getTaskService();
}
@Bean
public HistoryService historyService() throws Exception{
return processEngine().getObject().getHistoryService();
}
@Bean
public FormService formService() throws Exception{
return processEngine().getObject().getFormService();
}
@Bean
public IdentityService identityService() throws Exception{
return processEngine().getObject().getIdentityService();
}
}
2、创建一个测试controller写个部署流程的api
package com.ruoyi.act.controller;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author badcat
* @date 2021-08-23 0:25
*/
@RestController
@RequestMapping("/act")
public class ACT_Test {
@Autowired
private RepositoryService repositoryService;
/**
* 根据文件路径部署流程
*/
@GetMapping("/initDeploymentBPMN")
public String initDeploymentBPMN(){
String filename = "BPMN/test.bpmn";
Deployment deployment = this.repositoryService.createDeployment()
.addClasspathResource(filename)
.name("流程部署测试uel_v3")
.deploy();
return deployment.getName();
}
}
3、创建流程文件(流程文件自己想办法搞一个,或者去我码云上下载)
4、运行项目,登录后访问http://localhost/act/initDeploymentBPMN,看到如图所示就说明没毛病啊老铁
再看数据库里,流程资源表、流程部署表、流程定义表都有数据了
若依整合activiti工作已完成,这个算是里程碑性质了,所以码云上版本升到2.0吧。
这部分代码放到了码云https://gitee.com/study_badcat/ry_mp_activiti,v2.0分支。