Why do I write this because I just started to learn and read a lot on the Internet and stepped on a lot of pits. Finally, with the help of an enthusiastic netizen, I completed this Hello Activiti.
Recently, I have studied Activiti from scratch. There is a lot of information on the Internet. I have read about it and I am going to write a Demo. All the frameworks start from a Demo.
Because the company uses Springboot to build, so I use Springboot + Activiti to write a Demo
First is pom.xml
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>ibatis-core</artifactId>
<version>3.0</version>
</dependency>
<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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
properties configuration
spring.datasource.url=jdbc:mysql://localhost:3306/activiti-base?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#Automatically create, update, and verify database table structure
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
spring.activiti.check-process-definitions=false
Then draw a flowchart. I use STS. In fact, it is Eclipse. Just install an Activiti plug-in (Baidu by yourself).
Everyone, pay attention to the path of this file (a pit that a novice has stepped on)
After the flowchart is drawn, we can run it. As for those interface implementation classes, I haven't read it yet. After all, I'm also a novice.
Now tell everyone how to run this flowchart
The point is here. I have read so many blogs, but none of them told me that the process must be deployed before it can run.
So we deploy first
in your test class write
@Test
public void contextLoads() {
// 1. Deploy a process definition [I remember there are 3 ways]
Deployment deployment = repositoryService
.createDeployment() // Create a Deployment
.name("test process") // Give the process A name from
.addClasspathResource("processes/MyProcess.bpmn") // The path of bpmn You don't have a png image here, so use this one
.deploy();
System.out.println("Process deployment ID:" +deployment .getId());
System.out.println("Process deployment time:" +deployment.getDeploymentTime());
System.out.println("Process deployment name:" +deployment.getName());
then run
Then go to your database and have a look
You will find some more tables, these are the tables of activiti
After deployment, you will find the project you deployed in the act_re_deployment -> process deployment table, which means that your project is deployed and can now be run.
@Test
public void startProcessInstance() {
// ok let's start the process after deployment is complete
runtimeService.startProcessInstanceByKey("myProcess");
}
After running, act_hi_procinst -> process instance table In this table, you can see the instances of your flowchart run
When a process is deployed, there will be an instance in this table
Then you can observe the two tasks act_ru_task -> task table (tasks being executed), act_ho_taskinst -> historical tasks
There is already a record in the history task table. But his status is unfinished.
Look at the task table being executed, and there is also a piece of data in it. This is the currently executing task.
ok this little demo is done