Spring boot 集成 Activiti 工作流
发布于 2018-03-30    297 次阅读
本文主要介绍了,如何在Spring boot 集成 Activiti 工作流。使用的Spring boot版本为:1.4.3.RELEASE,使用的activiti版本为:5.21.0。

最终效果图

创建Spring boot项目,最终项目图如下:

Spring boot 集成 Activiti 工作流

 

pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.voidcc</groupId>
  <artifactId>activiti-test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent>

  <properties>
    <activiti.version>5.21.0</activiti.version>
  </properties>

  <dependencies>

    <!-- spring boot 配置 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- 热部署模块 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>

    <!-- 引入fastjson -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.15</version>
    </dependency>

    <!-- activiti 配置 -->
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring-boot-starter-basic</artifactId>
      <version>${activiti.version}</version>
    </dependency>

    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-engine</artifactId>
      <version>${activiti.version}</version>
    </dependency>

    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring</artifactId>
      <version>${activiti.version}</version>
    </dependency>

    <!-- mysql数据库配置 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.32</version>
    </dependency>

    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.27</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.10</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>

  </dependencies>

</project>

 

application.yml 配置

spring:
  application:
    name: activiti-test
  datasource:
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost:3306/activiti_test?useUnicode=true&characterEncoding=utf8
      username: 数据库账号
      password: 数据库密码
      druid:
        validationQuery: SELECT 1
        initialSize: 10
        minIdle: 10
        maxActive: 200
        minEvictableIdleTimeMillis: 180000
        testOnBorrow: false
        testWhileIdle: true
        removeAbandoned: true
        removeAbandonedTimeout: 1800
        logAbandoned: true
        poolPreparedStatements: true
        maxOpenPreparedStatements: 100
  activiti:
    check-process-definitions: false
  mvc:
    static-path-pattern: /**
security:
  basic:
    enabled: false
server:
  port: 9090

 

ActivitiConfig.java

package com.voidcc;

import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

@Configuration
public class ActivitiConfig {

  @Autowired
  PlatformTransactionManager transactionManager;

  @Autowired
  DataSource dataSource;

  @Bean
  public SpringProcessEngineConfiguration getProcessEngineConfiguration() {
    SpringProcessEngineConfiguration config =
        new SpringProcessEngineConfiguration();
    config.setDataSource(dataSource);
    config.setTransactionManager(transactionManager);
    config.setDatabaseType("mysql");
    config.setDatabaseSchemaUpdate("true");
    return config;
  }
}

 

WebApplication.java

package com.voidcc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WebApplication {

  public static void main(String[] args) {
    SpringApplication.run(WebApplication.class, args);
  }
}

 

数据库变化

创建一个database

CREATE DATABASE activiti_test;

运行WebApplication,Activiti会自动插入相关表,activiti_test数据库表现如下:

Spring boot 集成 Activiti 工作流

 

版权说明 : 本文为 开发小院 原创文章, 转载时请注明作者和原文连接

文章标题 : Spring boot 集成 Activiti 工作流

文章连接 : http://www.voidcc.com/content/spring-boot-integrate-activiti


 主题目录

    欢迎关注本站公众号 开发小院