背景:
公司业务模块场景中需要接入flowable流程引擎在连接启动中的问题记录
目录
相关资源:
flowable中文官网文档:
51CTO博客开源项目:
RuoYi-flowable: 基于RuoYi-vue + flowable 6.x 的工作流管理平台,提供流程管理、流程监控和任务调度等功能。具有易于集成、高度可定制和扩展性强的特点。
创建模块
右键->New->Module
Next->Finish
![](https://img-blog.csdnimg.cn/direct/a1d56096d17a4a2ebdc91b526b8b39af.png)
各xml添加相关配置
pom.xml(总pom)
<properties>
<!-- 略----已下是flowable流程引擎版本-->
<flowable.version>6.8.0</flowable.version>
</properties>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- 项目相关的------略 -->
<!-- flowable -->
<dependency>
<groupId>com.bonoon</groupId>
<artifactId>bvc-flowables</artifactId>
<version>${bvc.version}</version>
</dependency>
<!-- 工作流 -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 子模块 -->
<modules>
<module>flowables</module>
</modules>
pom.xml(admin)
<dependencies>
<!-- 项目相关的---略 -->
<!-- flowable -->
<dependency>
<groupId>com.xxxx</groupId>
<artifactId>xxx-flowables</artifactId>
</dependency>
</dependencies>
pom.xml(创建的flowables)
在创建的模块中接入flowable流程引擎
<dependencies>
<!-- 工作流-->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<!-- 排除flowable自带的权限认证 -->
<exclusions>
<exclusion>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-security</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<!-- websocket -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 通用工具-->
<dependency>
<groupId>com.bonoon</groupId>
<artifactId>bvc-common</artifactId>
<version>3.8.4</version>
</dependency>
<dependency>
<groupId>com.bonoon</groupId>
<artifactId>bvc-framework</artifactId>
<version>3.8.4</version>
</dependency>
</dependencies>
yml中添加相关配置
application-druid.yml[数据源配置]
#从库数据源
flowable: # flowable
enabled: true
url: jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: xxxxxx
application.yml[主配置源]
# flowable相关表
flowable:
# true 会对数据库中所有表进行更新操作。如果表不存在,则自动创建(建议开发时使用)
# false (默认): 当引擎启动时,检查数据库表结构的版本是否匹配库文件版本。版本不匹配时抛出异常。
# true: 构建引擎时,检查并在需要时更新表结构。表结构不存在则会创建。
# create-drop: 引擎创建时创建表结构,并在引擎关闭时删除表结构。
database-schema-update: false
# 关闭定时任务JOB
async-executor-activate: false
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: xxxxxx
当以上各种配好之后直接启动之前需要刷新一下maven进行本地仓库下载flowable的jar包
启动各种报错解决处理:
报错一:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flowable.spring.SpringProcessEngineConfiguration]: Factory method 'springProcessEngineConfiguration' threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.task.AsyncListenableTaskExecutor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=applicationTaskExecutor)}
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 122 common frames omitted
原因:
没有名为:applicationTaskExecutor线程可调用进行org.flowable.spring.SpringProcessEngineConfiguration相关线程的操作
解决办法:
找到项目中的ThreadPoolConfig类进行bean名创建
package com.bonoon.framework.config;
import com.bonoon.common.utils.Threads;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线程池配置
*
* @author ruoyi
**/
@Configuration
public class ThreadPoolConfig
{
// 核心线程池大小
private int corePoolSize = 50;
// 最大可创建的线程数
private int maxPoolSize = 200;
// 队列最大长度
private int queueCapacity = 1000;
// 线程池维护线程所允许的空闲时间
private int keepAliveSeconds = 300;
// @Bean(name = "threadPoolTaskExecutor")
// todo flowable需要applicationTaskExecutor的线程池
@Bean(name = {"threadPoolTaskExecutor","applicationTaskExecutor"})
public ThreadPoolTaskExecutor threadPoolTaskExecutor()
{
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setMaxPoolSize(maxPoolSize);
executor.setCorePoolSize(corePoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setKeepAliveSeconds(keepAliveSeconds);
// 线程池对拒绝任务(无线程可用)的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
DelegatingSecurityContextAsyncTaskExecutor delegate = new DelegatingSecurityContextAsyncTaskExecutor(executor); //包装线程池
return executor;
}
/**
* 执行周期性或定时任务
*/
@Bean(name = "scheduledExecutorService")
protected ScheduledExecutorService scheduledExecutorService()
{
return new ScheduledThreadPoolExecutor(corePoolSize,
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
new ThreadPoolExecutor.CallerRunsPolicy())
{
@Override
protected void afterExecute(Runnable r, Throwable t)
{
super.afterExecute(r, t);
Threads.printException(r, t);
}
};
}
}
报错二:
注:看控制台的第一个报错
原因:
springboot框架中自动配置中找不到flowable相关的配置类的bean注入到flowable引擎中
解决办法2.1:
查阅flowable相关官网文档可通过xml 添加相关配置。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="flowabledataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&ampzeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true"/>
<property name="username" value="root"/>
<property name="password" value="xxxxxx"/>
</bean>
<bean id="processEngineConfiguration"
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
<property name="dataSource" ref="flowabledataSource" />
<property name="databaseSchemaUpdate" value="false" />
</bean>
</beans>
可以看到以上的flowable.cfg.xml的bean并非报错所需的bean,任报错:
解决办法2.2:
添加配置类:FlowableDatabaseConfig
package com.bonoon.flowables.config;
import org.flowable.app.spring.SpringAppEngineConfiguration;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class FlowableDatabaseConfig {
@Bean(name = "processEngine")
public ProcessEngine processEngineConfiguration() {
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg.setJdbcUrl("jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true");
cfg.setJdbcUsername("root");
cfg.setJdbcPassword("xxxxxx");
cfg.setJdbcDriver("com.mysql.cj.jdbc.Driver");
cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
cfg.setAsyncExecutorActivate(false);
System.out.println("创建ProcessEnginebean成功");
return cfg.buildProcessEngine();
}
}
报错三:
最郁闷的报错:
原因:
flowable流程引擎启动有app相关的bean也需要一并创建。【推测:可能跟flowable版本有关。旧版本应该不会有这个报错】
解决办法:2.1
在原有配置类:FlowableDatabaseConfig 中创建方法
package com.bonoon.flowables.config;
import org.flowable.app.spring.SpringAppEngineConfiguration;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class FlowableDatabaseConfig {
@Bean(name = "processEngine")
public ProcessEngine processEngineConfiguration() {
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg.setJdbcUrl("jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true");
cfg.setJdbcUsername("root");
cfg.setJdbcPassword("xxxxxx");
cfg.setJdbcDriver("com.mysql.cj.jdbc.Driver");
cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
cfg.setAsyncExecutorActivate(false);
System.out.println("创建ProcessEnginebean成功");
return cfg.buildProcessEngine();
}
@Bean
public SpringAppEngineConfiguration appEngineConfiguration() {
SpringAppEngineConfiguration config = new SpringAppEngineConfiguration();
// config.setDataSource(dataSource);
config.setJdbcUrl("jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true");
config.setJdbcUsername("root");
config.setJdbcPassword("xxxxxx");
config.setJdbcDriver("com.mysql.cj.jdbc.Driver");
config.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); // 如果需要创建表
return config;
}
}
任报错:
通过百度及ai查询结果得知:没有配置bean方法的数据源默认使用的还是默认数据源的数据导致报这个错
解决办法:2.2
添加flowable数据源配置类:TransactionManagerConfig
package com.bonoon.flowables.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
public class TransactionManagerConfig {
// 自定义数据源中的连接数据源的方法----根据自己项目来写
@Autowired
@Qualifier("dbneflowableDataSource")
private DataSource flowableDataSource;
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(flowableDataSource);
}
}
在FlowableDatabaseConfig调整中调整
package com.bonoon.flowables.config;
import org.flowable.app.spring.SpringAppEngineConfiguration;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class FlowableDatabaseConfig {
@Autowired
@Qualifier("transactionManager")
private PlatformTransactionManager platformTransactionManager;
@Bean(name = "processEngine")
public ProcessEngine processEngineConfiguration() {
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg.setJdbcUrl("jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true");
cfg.setJdbcUsername("root");
cfg.setJdbcPassword("xxxxxx");
cfg.setJdbcDriver("com.mysql.cj.jdbc.Driver");
cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
cfg.setAsyncExecutorActivate(false);
System.out.println("创建ProcessEnginebean成功");
return cfg.buildProcessEngine();
}
@Bean
public SpringAppEngineConfiguration appEngineConfiguration() {
SpringAppEngineConfiguration config = new SpringAppEngineConfiguration();
// config.setDataSource(dataSource);
config.setJdbcUrl("jdbc:mysql://192.168.1.xxx:3306/flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true");
config.setJdbcUsername("root");
config.setJdbcPassword("xxxxxx");
config.setJdbcDriver("com.mysql.cj.jdbc.Driver");
config.setTransactionManager(platformTransactionManager); // 添加这一行
config.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); // 如果需要创建表
return config;
}
}
最后启动成功:
模块配置类:
写的不好,哪位大能有更好的意见!联系小编及时更正!!!