springboot 集成 activiti 流程引擎

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot 集成 activiti 流程引擎相关的知识,希望对你有一定的参考价值。

参考技术A  1. pom

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>2.5.2</version>

<relativePath /> <!-- lookup parent from repository -->

</parent>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

<shiro.version>1.4.0</shiro.version>

<activiti.version>6.0.0</activiti.version>

<batik.version>1.7</batik.version>

<maven-jar-plugin.version>3.0.0</maven-jar-plugin.version>

</properties>

        <!-- activiti -->

<dependency>

<groupId>org.activiti</groupId>

<artifactId>activiti-spring-boot-starter-basic</artifactId>

<version>$activiti.version</version>

<exclusions>

        <exclusion>

          <groupId>de.odysseus.juel</groupId>

          <artifactId>juel-spi</artifactId>

        </exclusion>

        <exclusion>

          <groupId>de.odysseus.juel</groupId>

          <artifactId>juel-api</artifactId>

        </exclusion>

      </exclusions>

</dependency>

<dependency>

    <groupId>org.activiti</groupId>

    <artifactId>activiti-json-converter</artifactId>

    <version>$activiti.version</version>

</dependency>

<!-- batik start -->

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-anim -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-anim</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-awt-util -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-awt-util</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-bridge -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-bridge</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-codec -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-codec</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-css -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-css</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-dom -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-dom</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-ext -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-ext</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-gvt -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-gvt</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-js -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-js</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-parser -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-parser</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-script -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-script</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svg-dom -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-svg-dom</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svggen -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-svggen</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-transcoder -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-transcoder</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-util -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-util</artifactId>

    <version>$batik.version</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-xml -->

<dependency>

    <groupId>org.apache.xmlgraphics</groupId>

    <artifactId>batik-xml</artifactId>

    <version>$batik.version</version>

</dependency>

2. 配置类

package org.fh.config;

import org.activiti.spring.SpringProcessEngineConfiguration;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.ApplicationContext;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.stereotype.Controller;

import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**

* 说明:Activiti配置

* from:www.fhadmin.cn

*/

@Controller

@Configuration

public class ActivitiConfig

@Autowired

PlatformTransactionManager transactionManager;

@Autowired

ApplicationContext applicationContext;

@Bean

public SpringProcessEngineConfiguration getProcessEngineConfiguration()

DataSource dataSource = applicationContext.getBean(DataSource.class);

SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();

config.setDataSource(dataSource);

config.setDbIdentityUsed(false);

config.setTransactionManager(transactionManager);

/**设置字体**/

config.setActivityFontName("宋体");

config.setLabelFontName("宋体");

config.setAnnotationFontName("宋体");

config.setDatabaseType("oracle");

return config;



SpringBoot2集成Activiti6

Activiti是领先的轻量级的,以Java为中心的开源BPMN(Business Process Modeling Notation)引擎,实现了真正的流程自动化。下面介绍如何在SpringBoot环境下使用Maven集成Activiti6,来实现流程开发。

添加依赖

  1. <dependency>
  2. <groupId>org.activiti</groupId>
  3. <artifactId>activiti-spring-boot-starter-basic</artifactId>
  4. <version>6.0.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-web</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-jdbc</artifactId>
  13. </dependency>

添加Processes目录

SpringBoot集成activiti默认会从classpath下的processes目录下读取流程定义文件,所以需要在src/main/resources目录下添加processes目录,并在目录中创建流程文件,添加目录后,目录结构变为:

技术图片

 

如果没有processes目录,则需要修改配置spring.activiti.process-definition-location-prefix,指定流程文件存放目录。

Spring集成Activiti6默认支持**.bpmn20.xml和**.bpmn格式的流程定义文件,修改支持的文件格式,通过配置spring.activiti.process-definition-location-suffixes修改

如:

  1. spring:
  2. activiti:
  3. check-process-definitions: true #自动检查、部署流程定义文件
  4. database-schema-update: true #自动更新数据库结构
  5. process-definition-location-prefix: classpath:/processes/ #流程定义文件存放目录
  6. #process-definition-location-suffixes: #流程文件格式
  7. # - **.bpmn20.xml
  8. # - **.bpmn

启动项目时,如果没有流程部署,就不能通过自动注入,使用RuntimeService等API,依赖注入时后报错。

ActivitiProperties中定义了activiti的自动配置项,其他配置请查看ActivitiProperties属性。

添加数据源

添加数据源,项目中添加数据源,初始化数据库结构,后续保存流程数据,

  1. spring :
  2. #data source config
  3. datasource :
  4. driver : com.mysql.jdbc.Driver
  5. url: jdbc:mysql://192.168.105.10:3306/test_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true
  6. username : root
  7. password : mysql
  8. initsize : 10
  9. maxActive : 20
  10. minIdle : 10
  11. maxWait : 120000
  12. poolPreparedStatements : false
  13. maxOpenPreparedStatements : -1
  14. validationQuery : select 1
  15. testOnborrow : true
  16. testOnReturn : true
  17. testWhileIdle : true
  18. timeBetweenEvictionRunsMillis : 120000
  19. filters : log4j,stat

添加流程

在项目中添加流程,创建文件simple.bpmn,添加内容

  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="Examples" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1539757531057" name="" targetNamespace="Examples" typeLanguage="http://www.w3.org/2001/XMLSchema">
  3. <process id="oneTaskProcess" isClosed="false" name="The One Task Process" processType="None">
  4. <startEvent id="theStart"/>
  5. <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask"/>
  6. <userTask activiti:assignee="$user" activiti:exclusive="true" id="theTask" name="my task"/>
  7. <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd"/>
  8. <endEvent id="theEnd"/>
  9. </process>
  10. </definitions>

启动测试

编写SpringBoot启动类,启动项目,启动项目。

  1. @SpringBootApplication(scanBasePackages = "com.legao.server")
  2. @EnableSwagger2
  3. public class WorkflowServer
  4. public static void main(String[] args)
  5. SpringApplication.run(WorkflowServer.class, args);

启动时,发现启动报错,

  1. Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
  2. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerMapping‘ defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

查看activiti-spring-boot-starter-basic-6.0.0.jar发现,org.activiti.spring.boot.SecurityAutoConfiguration编译报错,这时候将SecurityAutoConfiguration排除到SpringBoot启动之外,即@SpringBootApplication注解添加exclude = SecurityAutoConfiguration.class属性

  1. @SpringBootApplication(scanBasePackages = "com.legao.server", exclude = SecurityAutoConfiguration.class)
  2. @EnableSwagger2
  3. public class WorkflowServer
  4. public static void main(String[] args)
  5. SpringApplication.run(WorkflowServer.class, args);

再启动发现启动正常,这时候SpringBoot集成activiti已经启动成功,查看数据库,Activiti6运行所需的28张表也已经创建成功。

  1. ACT_EVT_LOG
  2. ACT_GE_BYTEARRAY
  3. ACT_GE_PROPERTY
  4. ACT_HI_ACTINST
  5. ACT_HI_ATTACHMENT
  6. ACT_HI_COMMENT
  7. ACT_HI_DETAIL
  8. ACT_HI_IDENTITYLINK
  9. ACT_HI_PROCINST
  10. ACT_HI_TASKINST
  11. ACT_HI_VARINST
  12. ACT_ID_GROUP
  13. ACT_ID_INFO
  14. ACT_ID_MEMBERSHIP
  15. ACT_ID_USER
  16. ACT_PROCDEF_INFO
  17. ACT_RE_DEPLOYMENT
  18. ACT_RE_MODEL
  19. ACT_RE_PROCDEF
  20. ACT_RU_DEADLETTER_JOB
  21. ACT_RU_EVENT_SUBSCR
  22. ACT_RU_EXECUTION
  23. ACT_RU_IDENTITYLINK
  24. ACT_RU_JOB
  25. ACT_RU_SUSPENDED_JOB
  26. ACT_RU_TASK
  27. ACT_RU_TIMER_JOB
  28. ACT_RU_VARIABLE

(完)

原文地址:https://blog.csdn.net/weihao_/article/details/83241662

以上是关于springboot 集成 activiti 流程引擎的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot2集成Activiti6

springboot集成activity

activiti流程图在线绘制业务申请审批流转跟进催办,springboot集成工作流基础框架

springboot集成activity6.0工作流引擎

activiti流程图在线绘制业务申请审批流转跟进催办,springboot集成工作流基础

37Springboot集成Flowable