mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-11 10:36:54 +08:00
Fix: nodeId 双向映射 beanName,相同 nodeId 打印报错信息
This commit is contained in:
@@ -6,7 +6,6 @@ import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.process.holder.SpringNodeIdHolder;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -57,7 +56,7 @@ public class AIComponentBeanPostProcessor implements BeanPostProcessor, Ordered
|
||||
|
||||
LOG.info("AI proxy component[{}] has been created for interface: {}", beanName, interfaceClass.getName());
|
||||
|
||||
String nodeId = StrUtil.isNotBlank(aiComponent.getNodeId()) ? aiComponent.getNodeId() : SpringNodeIdHolder.getRealBeanName(interfaceClass, beanName);
|
||||
String nodeId = StrUtil.isNotBlank(aiComponent.getNodeId()) ? aiComponent.getNodeId() : beanName;
|
||||
// 注册到FlowBus中(LiteFlow容器)
|
||||
FlowBus.addManagedNode(nodeId, aiComponent);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yomahub.liteflow.ai.proxy;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
@@ -9,10 +10,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
import org.springframework.beans.factory.support.*;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
@@ -98,13 +96,17 @@ public class AIComponentProxyRegistrar implements BeanDefinitionRegistryPostProc
|
||||
builder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
|
||||
|
||||
// 将 BeanDefinition 注册到 Spring 容器中
|
||||
String beanName = StringUtils.uncapitalize(interfaceClass.getSimpleName());
|
||||
// NodeId 与 BeanName 保持一致
|
||||
AIComponent anno = interfaceClass.getAnnotation(AIComponent.class);
|
||||
String beanName = StrUtil.isNotBlank(anno.nodeId()) ? anno.nodeId() : StringUtils.uncapitalize(interfaceClass.getSimpleName());
|
||||
registry.registerBeanDefinition(beanName, builder.getBeanDefinition());
|
||||
|
||||
LOG.info("Detected AI component interface: {}, registered as BeanDefinition with name: {}",
|
||||
interfaceClassName, beanName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new LiteFlowAIException("Failed to find AI component interface class", e);
|
||||
} catch (BeanDefinitionOverrideException e) {
|
||||
throw new LiteFlowAIException("bean name conflicts with existing bean definition", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,19 @@ public class SetUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果给定的值为 null 或 "空" 或 默认值,则调用消费者。
|
||||
*
|
||||
* @param consumer 要执行的操作。
|
||||
* @param value 要检查的值。
|
||||
* @param <T> 值的类型。
|
||||
*/
|
||||
public static <T> void setIfNotPresent(Consumer<T> consumer, T value) {
|
||||
if (isNullOrEmptyOrDefault(value)) {
|
||||
consumer.accept(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查给定的对象是否为 null 或 "空" 或 默认值
|
||||
* 如果一个对象是 String、Collection、Map 或数组,且其元素个数或长度为零,
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
THEN(a, aiCmpId, b);
|
||||
THEN(a, aiCmpId);
|
||||
</chain>
|
||||
</flow>
|
||||
|
||||
Reference in New Issue
Block a user