改变基础配置的方式

This commit is contained in:
bryan31 2021-03-19 13:25:05 +08:00
parent 784ff51505
commit b7b4cd6d66
5 changed files with 56 additions and 31 deletions

View File

@ -24,13 +24,11 @@ import java.util.concurrent.ConcurrentHashMap;
import cn.hutool.core.collection.BoundedPriorityQueue;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.util.SpringAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yomahub.liteflow.entity.data.DataBus;
import com.yomahub.liteflow.entity.monitor.CompStatistics;
import com.yomahub.liteflow.util.LimitQueue;
public class MonitorBus {

View File

@ -0,0 +1,14 @@
package com.yomahub.liteflow.springboot;
import com.yomahub.liteflow.spring.ComponentScaner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class LiteflowComponentScanerAutoConfiguration {
@Bean
public ComponentScaner componentScaner(){
return new ComponentScaner();
}
}

View File

@ -9,40 +9,26 @@ import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.spring.ComponentScaner;
import com.yomahub.liteflow.util.SpringAware;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import javax.swing.*;
import java.util.List;
@Configuration
@EnableConfigurationProperties({LiteflowProperty.class,LiteflowMonitorProperty.class})
@ConditionalOnProperty(prefix = "liteflow", name = "rule-source")
@ConditionalOnBean(LiteflowConfig.class)
@AutoConfigureAfter(LiteflowPropertyAutoConfiguration.class)
@Import(SpringAware.class)
@PropertySource(
name = "liteflow Default Properties",
name = "Liteflow Default Properties",
value = "classpath:/META-INF/liteflow-default.properties")
public class LiteflowAutoConfiguration {
@Bean
public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty){
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource(property.getRuleSource());
liteflowConfig.setSlotSize(property.getSlotSize());
liteflowConfig.setWhenMaxWaitSecond(property.getWhenMaxWaitSecond());
liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog());
liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit());
liteflowConfig.setDelay(liteflowMonitorProperty.getDelay());
liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod());
return liteflowConfig;
}
@Bean
public ComponentScaner componentScaner(LiteflowConfig liteflowConfig){
return new ComponentScaner();
}
public class LiteflowMainAutoConfiguration {
@Bean
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig){
@ -56,12 +42,7 @@ public class LiteflowAutoConfiguration {
}
@Bean
public SpringAware springAware(){
return new SpringAware();
}
@Bean
public LiteflowExecutorInit liteflowExecutorInit(FlowExecutor flowExecutor, SpringAware springAware){
public LiteflowExecutorInit liteflowExecutorInit(FlowExecutor flowExecutor){
return new LiteflowExecutorInit(flowExecutor);
}

View File

@ -0,0 +1,30 @@
package com.yomahub.liteflow.springboot;
import com.yomahub.liteflow.property.LiteflowConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@EnableConfigurationProperties({LiteflowProperty.class,LiteflowMonitorProperty.class})
@ConditionalOnProperty(prefix = "liteflow", name = "rule-source")
@PropertySource(
name = "Liteflow Default Properties",
value = "classpath:/META-INF/liteflow-default.properties")
public class LiteflowPropertyAutoConfiguration {
@Bean
public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty){
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource(property.getRuleSource());
liteflowConfig.setSlotSize(property.getSlotSize());
liteflowConfig.setWhenMaxWaitSecond(property.getWhenMaxWaitSecond());
liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog());
liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit());
liteflowConfig.setDelay(liteflowMonitorProperty.getDelay());
liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod());
return liteflowConfig;
}
}

View File

@ -1,4 +1,6 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yomahub.liteflow.springboot.LiteflowAutoConfiguration
com.yomahub.liteflow.springboot.LiteflowComponentScanerAutoConfiguration,\
com.yomahub.liteflow.springboot.LiteflowPropertyAutoConfiguration,\
com.yomahub.liteflow.springboot.LiteflowMainAutoConfiguration