Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate Activiti6 with SpringBoot1.5.9

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how SpringBoot1.5.9 integrates Activiti6. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. Create a Maven-based SpringBoot Web project at the following address

Https://start.spring.io/

two。 Add dependent files for the project

The pom.xml file is as follows

4.0.0

Activiti.demo

Activiti-demo

1.0-SNAPSHOT

War

Activiti-demo

Spring-activiti-demo

Org.springframework.boot

Spring-boot-starter-parent

1.5.9.RELEASE

UTF-8

UTF-8

1.8

Org.springframework.boot

Spring-boot-starter-web

Org.activiti

Activiti-spring-boot-starter-basic

6.0.0

Org.springframework.boot

Spring-boot-starter-data-jpa

Org.springframework.boot

Spring-boot-starter-thymeleaf

Mysql

Mysql-connector-java

Org.springframework.boot

Spring-boot-starter-test

Org.springframework.boot

Spring-boot-maven-plugin

3. Add business process files

Create a processes directory under the src/main/java/resource directory

Create a process.bpmn file with the following contents

4. Configure the application.properties file

The configuration is as follows

Spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activiti?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=UTF-8

Spring.datasource.username=root

Spring.datasource.password=123456

Spring.jpa.properties.hibernate.hbm2ddl.auto=update

Spring.jpa.show-sql=true

Server.port=8082

Server.context-path=/

Server.session.timeout=10

Server.tomcat.uri-encoding=UTF-8

5. Code implementation

a. Define Interfac

Package com.springboot.demo.service

Import org.springframework.web.bind.annotation.RequestMapping

Import org.springframework.web.bind.annotation.RequestMethod

Import org.springframework.web.bind.annotation.RestController

@ RestController

@ RequestMapping ("/ activityConsumerService")

Public interface ActivityConsumerService {

@ RequestMapping (value = "/ startActivityDemo", method = RequestMethod.GET)

Public boolean startActivityDemo ()

}

b. Implementation interface

Package com.springboot.demo.service.impl

Import com.springboot.demo.service.ActivityConsumerService

Import org.activiti.engine.RepositoryService

Import org.activiti.engine.RuntimeService

Import org.activiti.engine.TaskService

Import org.activiti.engine.impl.persistence.entity.ExecutionEntity

Import org.activiti.engine.task.Task

Import org.springframework.beans.factory.annotation.Autowired

Import org.springframework.stereotype.Service

Import java.util.HashMap

Import java.util.List

Import java.util.Map

/ * *

* @ ClassName ActivityConsumerServiceImpl

* @ Description TODO

* @ Author yunshuodeng

* @ Date 2019-04-29 13:28

* @ Version 1.0

* * /

@ Service ("activityService")

Public class ActivityConsumerServiceImpl implements ActivityConsumerService {

@ Autowired

Private RuntimeService runtimeService

@ Autowired

Private TaskService taskService

@ Autowired

Private RepositoryService repositoryService

@ Override

Public boolean startActivityDemo () {

/ / get the current method name

String methodName = Thread.currentThread () .getStackTrace () [1] .getMethodName ()

/ / define the task manager

String name1 = "zhangsan"

String name2 = "lisi"

System.out.println ("method" + methodName + "begin...")

/ / output number of process deployments

System.out.println ("call the process storage service to query the number of deployments" + repositoryService.createDeploymentQuery () .count ())

Map map = new HashMap ()

Map.put ("apply", name1)

Map.put ("approve", name2)

/ / process start

ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.startProcessInstanceByKey ("leave", map)

/ / query the task list of name1

List taskList = taskService.createTaskQuery () .taskAssignee (name1) .list ()

/ / output the number of tasks

System.out.println (taskList.size ())

If (taskList! = null & & taskList.size () > 0) {

For (Task task: taskList) {

System.out.println ("Task ID:" + task.getId ())

System.out.println ("Task Manager:" + task.getAssignee ())

System.out.println ("Task name:" + task.getName ())

System.out.println ("Task creation time:" + task.getCreateTime ())

System.out.println ("process instance ID:" + task.getProcessDefinitionId ())

System.out.println ("- -")

}

}

System.out.println ("method" + methodName + "end...")

Return false

}

}

6. Start the service and access it at the following address

Http://localhost:8082/activityConsumerService/startActivityDemo

7. Viewing the output of the console does not report an error indicating that the integration is complete.

This is the end of the article on "how to integrate SpringBoot1.5.9 with Activiti6". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report