mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
bug #I4MINM 加载脚本节点时,节点里面的实例对象被改动了
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package com.yomahub.liteflow.flow;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -102,9 +103,13 @@ public class FlowBus {
|
||||
try {
|
||||
//以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置
|
||||
//这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了
|
||||
NodeComponent cmpInstance = SpringAware.registerOrGet(cmpClazz);
|
||||
//如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance
|
||||
NodeComponent cmpInstance = null;
|
||||
if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.COND_SCRIPT).contains(type)){
|
||||
cmpInstance = SpringAware.registerOrGet(nodeId, cmpClazz);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNull(cmpInstance)) {
|
||||
LOG.warn("couldn't find component class [{}] from spring context", cmpClazz.getName());
|
||||
cmpInstance = cmpClazz.newInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -45,22 +46,25 @@ public class SpringAware implements ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T registerBean(Class<T> c) {
|
||||
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(c.getName(), beanDefinition);
|
||||
return getBean(c.getName());
|
||||
beanFactory.registerBeanDefinition(beanName, beanDefinition);
|
||||
return getBean(beanName);
|
||||
}
|
||||
|
||||
public static <T> T registerOrGet(Class<T> clazz) {
|
||||
T t = null;
|
||||
try {
|
||||
t = SpringAware.getBean(clazz);
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
if (t == null) {
|
||||
t = SpringAware.registerBean(clazz);
|
||||
}
|
||||
public static <T> T registerBean(Class<T> c) {
|
||||
return registerBean(c.getName(), c);
|
||||
}
|
||||
|
||||
public static <T> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
if (ObjectUtil.isNull(applicationContext)){
|
||||
return null;
|
||||
}
|
||||
T t = SpringAware.getBean(clazz);
|
||||
if (ObjectUtil.isNull(t)) {
|
||||
t = SpringAware.registerBean(beanName, clazz);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user