Activiti工作流框架學習筆記(二)之springboot2.0整合工作流Activiti6.0


以前在工作當中做過不少與工作流Activiti有關的工作,當時都是spring集成activiti5.22的項目,現在回過頭去看,其實版本已經稍微老了,因此,基於先前的工作經驗,決定用較新版本的技術來重新梳理下以前接觸過的技術。

決定用springboot2.0+Activiti6.0來做實踐總結。

第一步,在springboot項目pom.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的配置類

 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

image
出現這種問題主要是因為MySql的版本問題,在連接mysql的url后邊加一個&nullCatalogMeansCurrent=true即可解決。
再次運行后,成功創建了28張Activiti自帶的數據表——

接下來,將基於該搭建,對Activiti工作流引擎做更多操作實踐。

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM