How to start Activiti + Spring JPA with Spring Boot

In previous post, you was introduced BPMN and Activiti along with its API. This tutorial shows you a simple Spring Boot example which is integrated with Activiti and Spring JPA.

Related Articles:
Introduction to Activiti – a Java BPM Engine
Activiti Parallel Tasks + JPA with Spring Boot Example
Activiti REST API with Spring Boot Example

I. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.3.RELEASE

II. Overview
1. Goal

To build a Spring Boot application that helps to manage process as below:
activiti-jpa-springboot-process

– We will create a group of persons and use Spring JPA to store their information.
– Then we assign Task 1 and Task 2 to one of them who is called assignee.
– After he finishes 2 tasks, ‘final Notice’ message will be shown in the System Console.

2. Project Structure

activiti-jpa-springboot

– Process definition will be written under XML format in process/simple-process.bpmn20.xml file.
MyService provides service methods for Controller such as: startProcess(), getTasks(), completeTask(). Those functions can be done with help of some @Autowired objects which are instances of these classes:
+ RepositoryService
+ RuntimeService
+ TaskService
+ PersonRepository
PersonRepository is an interface extends JpaRepository for implementing repository methods on Person entities.

SpringStarterActivitiApplication class contains Bean that calls MyService‘s creating persons method when starting the application.
MyController is a REST Controller which has request mapping methods for RESTful requests such as: /process, /tasks, /completetask.

pom.xml contains dependencies for:
+ Activiti Spring Boot Starter Basic, Activiti Spring Boot Starter JPA
+ Spring Boot Starter Web
+ H2 database
+ Groovy: scripting engine for running Script Task in process.

Notes: We must add Groovy Jar file (groovy-all-2.4.10.jar) to make it work.
3. Step to do

We will follow these steps to make things done:
– Create Spring Boot project
– Define Process
– Create DataModel Class and JPA Repository Interface
– Create Service Class
– Create Application Class
– Create Controller
– Run & Check Result

III. Practice
1. Create Spring Maven project

– Using Spring Tool Suite to create Project and add Dependencies to pom.xml file:

– Add Groovy Jar file (groovy-all-2.4.10.jar) as Referenced Library.

2. Define Process

Under src/main/resources, create processes folder and add simple-process.bpmn20.xml file:

We use ${person.name} expression and activiti:assignee attribute for assigning task.

3. Create DataModel Class and JPA Repository Interface

4. Create Service Class

5. Create Application Class

6. Create Controller

7. Run & Check Result

– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results by open your browser and send request:

Request 1: Assign tasks to David
http://localhost:8080/process?assignee=David

Request 2: show tasks of David
http://localhost:8080/tasks/David

David has only one Task at the present because he hasn’t done the Task 1.

Request 3: complete Task 1
http://localhost:8080/completetask?id=8

Request 4: show tasks of David
http://localhost:8080/tasks/David

David now works on Task 2.

Request 5: complete Task 2
http://localhost:8080/completetask?id=11

And System Console shows:

IV. Source Code

SpringStarterActiviti


Related Posts



Got Something To Say:

Your email address will not be published. Required fields are marked *

*