springboot 2.2.0整合flowable 6.5.0

创建空的maven项目,并加入springboot 2.2.0、flowable依赖,以下是完整maven配置(pom.xml)




  4.0.0

  org.example
  flowable
  1.0-SNAPSHOT

  flowable
  
  http://www.example.com

  
    UTF-8
    1.8
    1.8
    2.2.0.RELEASE
    6.5.0
  

  
    org.springframework.boot
    spring-boot-starter-parent
    2.2.0.RELEASE
  

  
    
      junit
      junit
      4.11
      test
    

    
      org.springframework.boot
      spring-boot-starter-web
      ${spring-boot.version}
    

    
      org.flowable
      flowable-spring-boot-starter-process
      ${flowable.version}
    

    
      mysql
      mysql-connector-java
    

    
      com.alibaba
      druid
      1.1.21
    

    
    
      com.googlecode.cxs.log4jdbc
      cxs-log4jdbc
      0.0.1
    

  



配置ProcessEngine

package com.satuo20.flowable.config;

import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * @author xiaodx
 */
@Configuration
public class ProcessEngineConfig {

    /**
     * ProcessEngine 配置,其中DataSourceTransactionManager和DataSource自动注入
     * @param dataSourceTransactionManager
     * @param dataSource
     * @return
     */
    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSourceTransactionManager dataSourceTransactionManager,DataSource dataSource) {
        SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
        springProcessEngineConfiguration.setDataSource(dataSource);
        springProcessEngineConfiguration.setTransactionManager(dataSourceTransactionManager);

        //不添加此项配置,在没创建表时,会抛出FlowableWrongDbException异常
        springProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        return springProcessEngineConfiguration;
    }
}


数据源及flowable 相关配置application.yml

server:
  port: 8080

flowable:
  #关闭定时任务JOB
  async-executor-activate: false
  #  将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时,会自动将数据库表结构升级至新版本。
  database-schema-update: true


spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  datasource:
    driver-class-name: net.sf.log4jdbc.DriverSpy
#    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    # 如果不加这个参数,建表会失败:nullCatalogMeansCurrent=true
    url: jdbc:log4jdbc:mysql://10.0.10.225:3306/flowable_xiaodx?characterEncoding=UTF-8&rewriteBatchedStatements=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
#    url: jdbc:mysql://10.0.10.225:3306/flowable_xiaodx?characterEncoding=UTF-8&rewriteBatchedStatements=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    username: developer
    password: 123456
    druid:
      initial-size: 5
      max-active: 20
      max-pool-prepared-statement-per-connection-size: 20
      max-wait: 60000
      min-evictable-idle-time-millis: 300000
      min-idle: 5
      pool-prepared-statements: true
      test-on-borrow: false
      test-on-return: false
      test-while-idle: true
      time-between-eviction-runs-millis: 60000
      validation-query: SELECT 1 FROM DUAL
      max-idle: 4

启动类

package com.satuo20.flowable.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;


/**
 * @author xiaodx
 */
@SpringBootApplication
@ComponentScan("com.satuo20")
public class FlowableApp {
    public static void main(String[] args) {
        SpringApplication.run(FlowableApp.class,args);
    }
}

整合完成及总结

  • 使用springboot整合flowable非常简单
  • 在配置数据库时,如果抛出FlowableWrongDbException异常,请在spring.datasource.url中拼接参数nullCatalogMeansCurrent=true

你可能感兴趣的:(springboot 2.2.0整合flowable 6.5.0)