Activiti工作流框架学习笔记(二)之springboot2.0整合工作流Activiti6.0

文/朱季谦

以前在工作当中做过不少与工作流Activiti有关的工作,当时都是spring集成activiti5.22的项目,现在回过头去看,其实版本已经稍微老了,因此,基于先前的工作经验,决定用较新版本的技术来重新梳理下以前接触过的技术。

决定用springboot2.0+Activiti6.0来做实践总结。

第一步,在springboot项目pom.xml文件引入相关依赖:

XML 复制代码
 1 <!--Activiti 工作流-->
 2 <dependency>
 3     <groupId>mysql</groupId>
 4     <artifactId>mysql-connector-java</artifactId>
 5     <scope>5.1.35</scope>
 6 </dependency>
 7 
 8 <dependency>
 9     <groupId>org.activiti</groupId>
10     <artifactId>activiti-spring</artifactId>
11     <version>6.0.0</version>
12 </dependency>
13 
14 <dependency>
15     <groupId>com.fasterxml.jackson.core</groupId>
16     <artifactId>jackson-core</artifactId>
17     <version>2.9.5</version>
18 </dependency>

第二步,建立Activiti的配置类

java 复制代码
 1 @Configuration
 2 public class Activiticonfig {
 3 
 4     /**
 5      * 流程实例类,启动流程时创建
 6      * @return
 7      */
 8     @Bean
 9     public ProcessEngine processEngine(){
10           ProcessEngineConfiguration pro=ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
11           pro.setJdbcDriver("com.mysql.jdbc.Driver");
12           pro.setJdbcUrl("jdbc:mysql://localhost:3306/example?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC&nullCatalogMeansCurrent=true");
13           pro.setJdbcUsername("root");
14           pro.setJdbcPassword("root");
15           //避免发布的图片和xml中文出现乱码
16           pro.setActivityFontName("宋体");
17           pro.setLabelFontName("宋体");
18           pro.setAnnotationFontName("宋体");
19           pro.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
20           return pro.buildProcessEngine();
21     }
22 
23 
24     /**
25      * 仓库服务类,用于管理bpmn文件与流程图片
26      * @return
27      */
28     @Bean
29     public RepositoryService repositoryService(){
30         return processEngine().getRepositoryService();
31     }
32 
33     /**
34      * 流程运行服务类,用于获取流程执行相关信息
35      * @return
36      */
37     @Bean
38     public RuntimeService runtimeService(){
39         return processEngine().getRuntimeService();
40     }
41 
42     /**
43      * 任务服务类,用户获取任务信息
44      * @return
45      */
46     @Bean
47     public TaskService taskService(){
48         return processEngine().getTaskService();
49     }
50 
51 
52     /**
53      * 获取正在运行或已经完成的流程实例历史信息
54      * @return
55      */
56     @Bean
57     public HistoryService historyService(){
58         return processEngine().getHistoryService();
59     }
60 
61     /**
62      * 流程引擎的管理与维护
63      * @return
64      */
65     @Bean
66     public ManagementService managementService(){
67         return processEngine().getManagementService();
68     }
69 
70     /**
71      * 创建、更新、删除,查询群组和用户
72      * @return
73      */
74     @Bean
75     public IdentityService identityService(){
76         return processEngine().getIdentityService();
77     }
78 
79 }

在springboot工程里简单加完这些配置后,启动项目,原以为可以正常生成Activi6.0工作流自带的28张表,但这时出现了一堆错误:

复制代码
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Table 'example.act_ge_property' doesn't exist
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntityImpl.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_GE_PROPERTY where NAME_ = ?
### Cause: java.sql.SQLSyntaxErrorException: Table 'example.act_ge_property' doesn't exist
html 复制代码
出现这种问题主要是因为MySql的版本问题,在连接mysql的url后边加一个&nullCatalogMeansCurrent=true即可解决。
html 复制代码
再次运行后,成功创建了28张Activiti自带的数据表------

接下来,将基于该搭建,对Activiti工作流引擎做更多操作实践。

相关推荐
KoiHeng几秒前
操作系统简要知识
linux·笔记
巴伦是只猫1 小时前
【机器学习笔记Ⅰ】11 多项式回归
笔记·机器学习·回归
DKPT5 小时前
Java桥接模式实现方式与测试方法
java·笔记·学习·设计模式·桥接模式
巴伦是只猫6 小时前
【机器学习笔记Ⅰ】13 正则化代价函数
人工智能·笔记·机器学习
好好研究7 小时前
学习栈和队列的插入和删除操作
数据结构·学习
新中地GIS开发老师8 小时前
新发布:26考研院校和专业大纲
学习·考研·arcgis·大学生·遥感·gis开发·地理信息科学
SH11HF9 小时前
小菜狗的云计算之旅,学习了解rsync+sersync实现数据实时同步(详细操作步骤)
学习·云计算
Frank学习路上9 小时前
【IOS】XCode创建firstapp并运行(成为IOS开发者)
开发语言·学习·ios·cocoa·xcode
Chef_Chen10 小时前
从0开始学习计算机视觉--Day07--神经网络
神经网络·学习·计算机视觉
X_StarX12 小时前
【Unity笔记02】订阅事件-自动开门
笔记·学习·unity·游戏引擎·游戏开发·大学生