Activiti學習之spring boot 與activiti整合
1、新建spring boot 專案
使用IDEA新建一個spring boot 專案,專案結構如下:
2、增加activiti、jpa、mysql等依賴
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version> 5.21.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId >
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3、配置資料庫連線資訊
新建一個名為spring-boot-activiti的資料庫並且在application.properties中新增如下配置資訊:
##############################################################################
#########datasource
##############################################################################
spring.datasource.url=jdbc:mysql://localhost:3306/spring-boot-activiti?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#自動建立、更新、驗證資料庫表結構
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
4、新建activiti流程圖
這裡是通過Eclipse的activiti外掛繪製的流程圖,在圖中紅框部分新增如下程式碼:${resumeService.storeResume()}
流程圖的程式碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
<serviceTask id="servicetask1" name="User Task" activiti:expression="${resumeService.storeResume()}"></serviceTask>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="130.0" y="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="360.0" y="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="210.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="165.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="210.0" y="287.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="315.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="360.0" y="287.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
圖中的任務為系統任務,當執行到該任務時系統會根據配置資訊自動執行該任務
5、新建Service介面和實現類
public interface ResumeService {
void storeResume();
}
@Service("resumeService")
public class ResumeServiceImpl implements ResumeService {
@Override
public void storeResume() {
System.out.println("任務已經執行.....................................");
}
}
6、新建一個測試類來啟動這個流程
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SpringBootActivitiApplication.class)
public class ActivitiTest {
@Autowired
RuntimeService runtimeService;
@Test
public void TestStartProcess() {
Map<String, Object> variables = new HashMap<>();
variables.put("applicantName", "John Doe");
variables.put("email", "[email protected]");
variables.put("phoneNumber", "123456789");
runtimeService.startProcessInstanceByKey("myProcess", variables);
}
}
startProcessInstanceByKey()為根據流程ID啟動該流程的方法
7、執行完成
相關推薦
Activiti學習之spring boot 與activiti整合
1、新建spring boot 專案 使用IDEA新建一個spring boot 專案,專案結構如下: 2、增加activiti、jpa、mysql等依賴 <dependencies> <dependency&
Spring Boot 與 Activiti 6 錯誤記錄
Spring Boot 與 Activiti 6 錯誤記錄 Spring Boot 2.x 與 Activiti 6 整合的錯誤記錄 1. 在啟動類上排除排除SecurityAutoConfiguration類 起因:升級Spri
Spring Boot與Log4j2整合之java.lang.IllegalStateException: Logback configuration error detected:
引言: 一個問題的分析與解決過程是表與裡的過程,是一個大膽猜測與小心求證的過程,spring boot與log4j2的整合過程中,我將描述一下分析這個問題的思路和過程。 我一直強調一點: 重要的不是解決問題的結論,而是解決問題的思路和方法,即使在解決完問題之後,
Spring Boot學習筆記——Spring Boot與Redis的集成
pac urn prope web property static 接口 per select 一.添加Redis緩存 1.添加Redis起步依賴 在pom.xml中添加Spring Boot支持Redis的依賴配置,具體如下: <dependency>
6、Spring Boot 與MyBatis整合
1.6 Spring Boot 與MyBatis整合 簡介 詳細介紹如何在Spring Boot中整合MyBatis,並通過註解方式實現對映。 完整原始碼: 1.6.1 建立 spring-boot-mybatis 專案 pom檔案如下 <?xml version="1
7、Spring Boot 與 Redis 整合
1.7 Spring Boot 與 Redis 整合 簡介 繼續上篇的MyBatis操作,詳細介紹在Spring Boot中使用RedisCacheManager作為快取管理器,整合業務於一體。 完整原始碼: Spring-Boot-Demos 1.7.1 建立 spring-boot-r
Spring Boot與React整合
前言 前不久學習了Web開發,用React寫了前端,Spring Boot搭建了後端,然而沒有成功地把兩個工程結合起來,造成前端與後端之間需要跨域通訊,帶來了一些額外的工作。 這一次成功地將前端工程與後端結合在一個Project中,記錄一下,也希望能幫到那些和我一樣的入門小白。 環境 Win
Spring Boot與Quartz整合
1.匯入依賴包 <!-- quartz定時器 --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artif
spring boot與junit整合測試
先建立一個REST介面 package com.laoxu.gamedog.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframew
spring boot 與 mybatis整合
本專案使用的環境: 開發工具:Intellij IDEA 2018.1.3 springboot: 2.0.5.RELEASE jdk:1.8.0_161 maven:3.5.3 首先先建立springboot專案 選擇需要的模組 填寫包名 1.開始在專案
Spring Boot學習之Spring Boot的核心(三)
1、Spring Boot的專案一般都會有*Application的入口類,入口類中會有main方法,這是一個標準的Java應用程式的入口方法。 @SpringBootApplication註解是Spring Boot的核心註解,它其實是一個組合註解:下面我們
spring boot 與 Mybatis整合(*)
業務層 tomcat ng- quest map big selectall esp 連接 在pom.xml文件中加入數據庫、spring-mybatis整合 <!-- spring boot 整合mybatis --> <de
【SpringBoot學習之路】09.Spring Boot與日誌
轉載宣告:商業轉載請聯絡作者獲得授權,非商業轉載請註明出處.原文來自 © 呆萌鍾 【SpringBoot學習之路】09.Spring Boot與日誌 日誌框架 市場上存在非常多的日誌框架。JUL(java.util.logging),JCL(Apache
spring boot 2.2整合activiti 工作流
pom 檔案新增jar <!--jwt token--> <dependency> <groupId>com.auth0</groupId> <
Spring Boot學習筆記(二二) - 與Mybatis整合
Mybatis整合 Spring Boot中的JPA部分預設是使用的hibernate,而如果想使用Mybatis的話就需要自己做一些配置。使用方式有兩種,第一種是Mybatis官方提供的 mybatis-spring-boot-starter ,第二種是類似&nb
spring boot學習1 之 spring boot整合freemark、mybatis搭建專案
1. application.properties常用配置 server.port=9090 # 服務埠號 server.tomcat.uri-encoding=UTF-8 #以Tomcat為web容器
spring boot與jdbcTemplate的整合案例2
database bean n) ret struct mapping rri ott mode 簡單入門了spring boot後,接下來寫寫跟數據庫打交道的案例。博文采用spring的jdbcTemplate工具類與數據庫打交道。 下面是搭建的springbo
SpringBoot之旅 -- 定時任務兩種(Spring Schedule 與 Quartz 整合 )實現
目的 config object cnblogs java title cor 進行 eat 相關文章 Spring Boot 相關文章目錄 前言 最近在項目中使用到定時任務,之前一直都是使用Quartz 來實現,最近看Spring 基礎發現其實Spring 提供
spring boot 與 shiro的簡單整合使用
scheduler div turn map 用戶 ttr algorithm pen enc shrio官網:https://shiro.apache.org/ Apache Shiro是一個功能強大且易於使用的Java安全框架,可執行身份驗證,授權,加密和會話管理。借助
Spring Cloud、Spring Boot與Docker 學習資料匯總
space 學習資料 muc 配套 -s ring blog sta com 使用Spring Cloud與Docker實戰微服務https://gitee.com/itmuch/spring-cloud-bookhttps://eacdy.gitbooks.io/spri