enhancement #I5RV3G 规则插件的报错无法抛出来

This commit is contained in:
everywhere.z
2022-10-24 11:49:10 +08:00
parent 310454929b
commit 4e7d188135
5 changed files with 43 additions and 39 deletions

View File

@@ -35,9 +35,11 @@ public class ComponentInitializer {
nodeComponent.setType(type);
//设置MonitorBus如果没有就不注入
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
if(ObjectUtil.isNotNull(monitorBus)){
nodeComponent.setMonitorBus(monitorBus);
if (ContextAwareHolder.loadContextAware().hasBean("monitorBus")){
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
if(ObjectUtil.isNotNull(monitorBus)){
nodeComponent.setMonitorBus(monitorBus);
}
}
//先取传进来的name值(配置文件中配置的),再看有没有配置@LiteflowComponent标注

View File

@@ -19,4 +19,6 @@ public interface ContextAware extends SpiPriority {
<T> T registerBean(String beanName, Object bean);
<T> T registerOrGet(String beanName, Class<T> clazz);
boolean hasBean(String beanName);
}

View File

@@ -40,6 +40,11 @@ public class LocalContextAware implements ContextAware {
return registerBean(beanName, clazz);
}
@Override
public boolean hasBean(String beanName) {
return false;
}
@Override
public int priority() {
return 2;

View File

@@ -11,6 +11,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
/**
@@ -27,14 +28,17 @@ import org.springframework.context.annotation.Import;
@Import(SpringAware.class)
public class LiteflowMainAutoConfiguration {
//实例化ComponentScanner
//多加一个SpringAware的意义是确保在执行这个的时候SpringAware这个bean已经被初始化
@Bean
public ComponentScanner componentScanner(LiteflowConfig liteflowConfig){
public ComponentScanner componentScanner(LiteflowConfig liteflowConfig, SpringAware springAware){
return new ComponentScanner(liteflowConfig);
}
//实例化FlowExecutor
//多加一个SpringAware的意义是确保在执行这个的时候SpringAware这个bean已经被初始化
@Bean
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig) {
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig, SpringAware springAware) {
FlowExecutor flowExecutor = new FlowExecutor();
flowExecutor.setLiteflowConfig(liteflowConfig);
return flowExecutor;
@@ -47,9 +51,11 @@ public class LiteflowMainAutoConfiguration {
return new LiteflowExecutorInit(flowExecutor);
}
@Bean
//实例化MonitorBus
//多加一个SpringAware的意义是确保在执行这个的时候SpringAware这个bean已经被初始化
@Bean("monitorBus")
@ConditionalOnProperty(prefix = "liteflow", name = "monitor.enable-log", havingValue = "true")
public MonitorBus monitorBus(LiteflowConfig liteflowConfig) {
public MonitorBus monitorBus(LiteflowConfig liteflowConfig, SpringAware springAware) {
return new MonitorBus(liteflowConfig);
}
}

View File

@@ -34,45 +34,29 @@ public class SpringAware implements ApplicationContextAware, ContextAware {
@Override
public <T> T getBean(String name) {
try{
T t = (T) applicationContext.getBean(name);
return t;
}catch (Exception e){
return null;
}
T t = (T) applicationContext.getBean(name);
return t;
}
@Override
public <T> T getBean(Class<T> clazz) {
try{
T t = applicationContext.getBean(clazz);
return t;
}catch (Exception e){
return null;
}
T t = applicationContext.getBean(clazz);
return t;
}
private <T> T getBean(String beanName, Class<T> clazz) {
try{
T t = applicationContext.getBean(beanName, clazz);
return t;
}catch (Exception e){
return null;
}
T t = applicationContext.getBean(beanName, clazz);
return t;
}
@Override
public <T> T registerBean(String beanName, Class<T> c) {
try{
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory();
BeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClassName(c.getName());
beanFactory.setAllowBeanDefinitionOverriding(true);
beanFactory.registerBeanDefinition(beanName, beanDefinition);
return getBean(beanName);
}catch (Exception e){
return ReflectUtil.newInstance(c);
}
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory();
BeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClassName(c.getName());
beanFactory.setAllowBeanDefinitionOverriding(true);
beanFactory.registerBeanDefinition(beanName, beanDefinition);
return getBean(beanName);
}
@Override
@@ -93,11 +77,16 @@ public class SpringAware implements ApplicationContextAware, ContextAware {
if (ObjectUtil.isNull(applicationContext)){
return null;
}
T t = getBean(beanName, clazz);
if (ObjectUtil.isNull(t)) {
t = registerBean(beanName, clazz);
try{
return getBean(beanName, clazz);
}catch (Exception e){
return registerBean(beanName, clazz);
}
return t;
}
@Override
public boolean hasBean(String beanName){
return applicationContext.containsBean(beanName);
}
@Override