From 0a9d42cf77034221e187920dc9563ec5f71632a3 Mon Sep 17 00:00:00 2001 From: huangqizhen <15552608129@163.com> Date: Fri, 26 Sep 2025 10:00:38 +0800 Subject: [PATCH] =?UTF-8?q?9.20=20=E6=9B=B4=E6=96=B0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../java/com/example/demo/DemoApplication.java | 6 ++- .../demo/config/FlowableDataSourceConfig.java | 34 +++++++++++++ .../demo/config/work/FlowableEngineConfig.java | 56 ++++++++++++++++++++++ src/main/resources/application-dev.yml | 11 ++++- src/main/resources/application-test.yml | 13 ++++- 6 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/demo/config/FlowableDataSourceConfig.java create mode 100644 src/main/java/com/example/demo/config/work/FlowableEngineConfig.java diff --git a/pom.xml b/pom.xml index 031dec6..27623e8 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,11 @@ spring-boot-starter-web + org.flowable + flowable-spring-boot-starter + 7.0.0 + + org.springframework.boot spring-boot-starter-aop diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index e7293f0..93e87f5 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -1,12 +1,16 @@ package com.example.demo; + +import org.flowable.spring.boot.ProcessEngineAutoConfiguration; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; -@SpringBootApplication @EnableScheduling // 启用调度功能 +@SpringBootApplication(exclude = { + ProcessEngineAutoConfiguration.class, +}) @MapperScan(basePackages = "com.example.demo.mapper.coin", sqlSessionTemplateRef = "mysql1SqlSessionTemplate") @MapperScan(basePackages = "com.example.demo.mapper.bean", sqlSessionTemplateRef = "mysql2SqlSessionTemplate") @MapperScan(basePackages = "com.example.demo.mapper.pay", sqlSessionTemplateRef = "mysql3SqlSessionTemplate") diff --git a/src/main/java/com/example/demo/config/FlowableDataSourceConfig.java b/src/main/java/com/example/demo/config/FlowableDataSourceConfig.java new file mode 100644 index 0000000..1fe189b --- /dev/null +++ b/src/main/java/com/example/demo/config/FlowableDataSourceConfig.java @@ -0,0 +1,34 @@ +// FlowableDataSourceConfig.java +package com.example.demo.config; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; + +@Configuration +public class FlowableDataSourceConfig { + + @Bean(name = "flowableDataSource") + @ConfigurationProperties(prefix = "spring.datasource.flowable") + public DataSource flowableDataSource() { + HikariDataSource ds = DataSourceBuilder + .create() + .type(HikariDataSource.class) + .build(); + ds.setConnectionInitSql("SET SESSION sql_mode='TRADITIONAL';"); + return ds; + } + + @Bean(name = "flowableTransactionManager") + public PlatformTransactionManager flowableTransactionManager( + @Qualifier("flowableDataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java b/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java new file mode 100644 index 0000000..30e24e9 --- /dev/null +++ b/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java @@ -0,0 +1,56 @@ +// FlowableEngineConfig.java +package com.example.demo.config.work; + +import org.flowable.common.engine.impl.history.HistoryLevel; +import org.flowable.engine.HistoryService; +import org.flowable.engine.RepositoryService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.TaskService; + +import org.flowable.spring.SpringProcessEngineConfiguration; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; + +@Configuration +public class FlowableEngineConfig { + + @Bean + public SpringProcessEngineConfiguration processEngineConfiguration( + @Qualifier("flowableDataSource") DataSource flowableDataSource, + @Qualifier("flowableTransactionManager") PlatformTransactionManager transactionManager) { + + SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration(); + config.setDataSource(flowableDataSource); // 👈 指定 Flowable 数据源 + config.setTransactionManager(transactionManager); + config.setDatabaseSchemaUpdate("true"); // 自动建表 + config.setHistoryLevel(HistoryLevel.FULL).setAsyncExecutorActivate(false); // 记录完整历史 + // 暂时关闭异步执行器 + + return config; + } + + // 👇 以下 Service Bean 可选,但推荐注入,方便 Controller 使用 + @Bean + public RepositoryService repositoryService(SpringProcessEngineConfiguration config) { + return config.buildProcessEngine().getRepositoryService(); + } + + @Bean + public RuntimeService runtimeService(SpringProcessEngineConfiguration config) { + return config.buildProcessEngine().getRuntimeService(); + } + + @Bean + public TaskService taskService(SpringProcessEngineConfiguration config) { + return config.buildProcessEngine().getTaskService(); + } + + @Bean + public HistoryService historyService(SpringProcessEngineConfiguration config) { + return config.buildProcessEngine().getHistoryService(); + } +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 6a381df..9afe9e6 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -48,6 +48,14 @@ spring: username: gjb_test password: qweuio!@#$2 driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + flowable: + jdbc-url: jdbc:mysql://localhost:3306/flowable?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&allowMultiQueries=true&rewriteBatchedStatements=true + username: hwgoldc + password: zB48T55wCsHC8KPz + driver-class-name: com.mysql.cj.jdbc.Driver + hikari: + pool-name: flowableHikariCP + maximum-pool-size: 10 application: name: demo @@ -98,5 +106,4 @@ bean: url: http://39.101.133.168:8828/hljwgo/api/wallet/recharge consume: url: http://39.101.133.168:8828/hljwgo/api/wallet/pay -server: - port: 10704 +server: \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index bb697d8..b4c62ea 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -48,7 +48,18 @@ spring: username: gjb_test password: qweuio!@#$2 driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver - + flowable: + jdbc-url: jdbc:mysql://54.255.212.181:3306/flowable?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&allowMultiQueries=true&rewriteBatchedStatements=true + username: flowable + password: bN8NLHLAreSWTEZB + driver-class-name: com.mysql.cj.jdbc.Driver + hikari: + pool-name: FlowableHikariPool + maximum-pool-size: 20 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1200000 application: name: demo cache: