千家信息网

SpringBoot1.5.9如何集成Activiti6

发表于:2024-10-26 作者:千家信息网编辑
千家信息网最后更新 2024年10月26日,这篇文章将为大家详细讲解有关SpringBoot1.5.9如何集成Activiti6,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.通过以下地址创建基于Maven
千家信息网最后更新 2024年10月26日SpringBoot1.5.9如何集成Activiti6

这篇文章将为大家详细讲解有关SpringBoot1.5.9如何集成Activiti6,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1.通过以下地址创建基于Maven的SpringBoot Web项目

https://start.spring.io/

2.添加项目的依赖文件

pom.xml文件如下

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

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.添加业务流程文件

在src/main/java/resource目录下创建processes目录

创建process.bpmn文件,内容如下

4.配置application.properties文件

配置内容如下

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.代码实现

a.定义接口

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.实现接口

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() {

// 获取当前方法名

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

// 定义任务办理人

String name1 = "zhangsan";

String name2 = "lisi";

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

// 输出流程部署数量

System.out.println("调用流程存储服务,查询部署数量" + repositoryService.createDeploymentQuery().count());

Map map = new HashMap<>();

map.put("apply",name1);

map.put("approve",name2);

// 流程启动

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

// 查询name1的任务列表

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

// 输出任务数量

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

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

for (Task task : taskList){

System.out.println("任务ID:"+task.getId());

System.out.println("任务办理人:"+task.getAssignee());

System.out.println("任务名称:"+task.getName());

System.out.println("任务创建时间:"+task.getCreateTime());

System.out.println("流程实例ID:"+task.getProcessDefinitionId());

System.out.println("-------------------------------------------");

}

}

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

return false;

}

}

6.启动服务并通过以下地址进行访问

http://localhost:8082/activityConsumerService/startActivityDemo

7.查看控制台输出内容并不报错表示已整合完成

关于"SpringBoot1.5.9如何集成Activiti6"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

0