mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
对springAware进行一些修改
This commit is contained in:
@@ -3,6 +3,7 @@ package com.yomahub.liteflow.entity.executor;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.yomahub.liteflow.util.SpringAware;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -60,7 +61,7 @@ public class NodeExecutorHelper {
|
||||
// 此处无需使用同步锁进行同步-因为即使同时创建了两个实例,但是添加到缓存中的只会存在一个且不会存在并发问题-具体是由ConcurrentMap保证
|
||||
if (ObjectUtil.isNull(nodeExecutor)) {
|
||||
// 获取重试执行器实例
|
||||
nodeExecutor = ReflectUtil.newInstance(nodeExecutorClass);
|
||||
nodeExecutor = SpringAware.registerBean(nodeExecutorClass);
|
||||
// 缓存
|
||||
nodeExecutorMap.put(nodeExecutorClass, nodeExecutor);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -47,11 +48,15 @@ public class SpringAware implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
public static <T> T registerBean(String beanName, Class<T> c) {
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDefinition = new GenericBeanDefinition();
|
||||
beanDefinition.setBeanClassName(c.getName());
|
||||
beanFactory.registerBeanDefinition(beanName, beanDefinition);
|
||||
return getBean(beanName);
|
||||
try{
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDefinition = new GenericBeanDefinition();
|
||||
beanDefinition.setBeanClassName(c.getName());
|
||||
beanFactory.registerBeanDefinition(beanName, beanDefinition);
|
||||
return getBean(beanName);
|
||||
}catch (Exception e){
|
||||
return ReflectUtil.newInstance(c);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T registerBean(Class<T> c) {
|
||||
|
||||
Reference in New Issue
Block a user