From 465cc8cd3f4b90557df66d537d4b3566a4a96d3d Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Mon, 6 Jan 2025 10:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96spring=20boot=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0manager?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/SpringFlowableAutoConfiguration.java | 21 ++++++++++++++++--- .../jpa/SpringFlowableConfiguration.java | 2 -- .../jpa/SpringFlowableManagerInitializer.java | 11 ++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManagerInitializer.java diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableAutoConfiguration.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableAutoConfiguration.java index 6df7363..699d5dc 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableAutoConfiguration.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableAutoConfiguration.java @@ -6,11 +6,14 @@ import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository; import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableHistoryRepository; import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableInstanceRepository; import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableNodeRepository; -import org.springframework.beans.factory.annotation.Qualifier; +import java.util.Map; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; /** * 自动配置 @@ -19,9 +22,12 @@ import org.springframework.context.annotation.Configuration; * @version 20250103 */ @Configuration +@EnableJpaRepositories("com.lanyuanxiaoyao.flowable.jpa.repository") @EnableConfigurationProperties(SpringFlowableConfiguration.class) public class SpringFlowableAutoConfiguration { + @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Bean + @ConditionalOnMissingBean(FlowableRepository.class) public FlowableRepository flowableRepository( FlowableNodeRepository flowableNodeRepository, FlowableInstanceRepository flowableInstanceRepository, @@ -31,11 +37,20 @@ public class SpringFlowableAutoConfiguration { } @Bean + @ConditionalOnBean(FlowableRepository.class) + @ConditionalOnMissingBean(FlowableManager.class) public FlowableManager flowableManager( - @Qualifier("springFlowableConfiguration") FlowableConfiguration configuration, + FlowableConfiguration configuration, FlowableRepository repository, ApplicationContext applicationContext ) { - return new SpringFlowableManager(configuration, repository, applicationContext); + FlowableManager manager = new SpringFlowableManager(configuration, repository, applicationContext); + + Map initializerMap = applicationContext.getBeansOfType(SpringFlowableManagerInitializer.class); + for (SpringFlowableManagerInitializer initializer : initializerMap.values()) { + manager = initializer.initial(manager); + } + + return manager; } } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableConfiguration.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableConfiguration.java index 6b80dfb..ec562bb 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableConfiguration.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableConfiguration.java @@ -3,7 +3,6 @@ package com.lanyuanxiaoyao.flowable.jpa; import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; import lombok.ToString; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; /** * 配置类 @@ -12,7 +11,6 @@ import org.springframework.context.annotation.Configuration; * @version 20250103 */ @ToString(callSuper = true) -@Configuration @ConfigurationProperties("flowable") public class SpringFlowableConfiguration extends FlowableConfiguration { } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManagerInitializer.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManagerInitializer.java new file mode 100644 index 0000000..6fe4220 --- /dev/null +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManagerInitializer.java @@ -0,0 +1,11 @@ +package com.lanyuanxiaoyao.flowable.jpa; + +import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager; + +/** + * @author lanyuanxiaoyao + * @version 20250106 + */ +public interface SpringFlowableManagerInitializer { + FlowableManager initial(FlowableManager manager); +}