Skip to content

Commit 8c568ac

Browse files
committed
修改匿名类
1 parent cf947e1 commit 8c568ac

5 files changed

Lines changed: 107 additions & 89 deletions

File tree

.github/workflows/pr-title-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PR Title Check
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened, edited, synchronize]
66

77
permissions:

framework/fel/java/fel-starters/fel-spring-boot-starter/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<artifactId>fit-spring-boot-starter</artifactId>
2323
<version>${fit.version}</version>
2424
</dependency>
25+
2526
<!-- FEL 核心:需要访问核心接口 -->
2627
<dependency>
2728
<groupId>org.fitframework.fel</groupId>

framework/fel/java/fel-starters/fel-spring-boot-starter/src/main/java/modelengine/fel/starter/spring/FelSpringBootAutoConfiguration.java

Lines changed: 101 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -56,100 +56,115 @@ public class FelSpringBootAutoConfiguration {
5656
*/
5757
@Bean
5858
public static BeanDefinitionRegistryPostProcessor felBeanAutoRegistrar() {
59-
return new BeanDefinitionRegistryPostProcessor() {
60-
@Override
61-
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
62-
// 不需要在这里处理
63-
}
59+
return new FelBeanAutoRegistrar();
60+
}
6461

65-
@Override
66-
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
67-
LOG.info("Installing FEL Bean auto-registration processor");
68-
beanFactory.addBeanPostProcessor(new org.springframework.beans.factory.config.BeanPostProcessor() {
69-
private boolean registered = false;
70-
71-
@Override
72-
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
73-
if (!registered && bean instanceof FitRuntime) {
74-
registered = true;
75-
registerFelBeansToSpring((FitRuntime) bean, beanFactory);
76-
}
77-
return bean;
78-
}
79-
});
80-
}
62+
/**
63+
* FEL Bean 自动注册器,负责将 FIT 容器中的 FEL Bean 注册到 Spring 容器。
64+
*/
65+
private static class FelBeanAutoRegistrar implements BeanDefinitionRegistryPostProcessor {
66+
@Override
67+
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
68+
// 不需要在这里处理
69+
}
70+
71+
@Override
72+
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
73+
LOG.info("Installing FEL Bean auto-registration processor");
74+
beanFactory.addBeanPostProcessor(new FitRuntimeDetectorBeanPostProcessor(beanFactory));
75+
}
76+
}
8177

82-
/**
83-
* 将 FIT 容器中符合白名单的 FEL Bean 注册到 Spring 容器。
84-
*
85-
* @param fitRuntime FIT 运行时实例
86-
* @param beanFactory Spring Bean 工厂
87-
*/
88-
private void registerFelBeansToSpring(FitRuntime fitRuntime, ConfigurableListableBeanFactory beanFactory) {
89-
LOG.info("Auto-registering FEL beans to Spring container (whitelist mode)");
90-
try {
91-
BeanContainer container = fitRuntime.root().container();
92-
List<BeanFactory> allFactories = container.all();
93-
LOG.debug("Found {} beans in FIT container", allFactories.size());
94-
95-
int registeredCount = 0;
96-
int skippedCount = 0;
97-
int filteredCount = 0;
98-
99-
for (BeanFactory factory : allFactories) {
100-
BeanMetadata metadata = factory.metadata();
101-
String beanName = metadata.name();
102-
Type beanType = metadata.type();
103-
String typeName = beanType.getTypeName();
104-
105-
// 检查是否在白名单中(使用字符串匹配,支持子类)
106-
boolean isRequired = REQUIRED_BEAN_TYPE_NAMES.stream().anyMatch(requiredTypeName -> {
107-
try {
108-
Class<?> actualType = Class.forName(typeName);
109-
Class<?> requiredType = Class.forName(requiredTypeName);
110-
return requiredType.isAssignableFrom(actualType);
111-
} catch (ClassNotFoundException e) {
112-
// 某些可选依赖的类可能不在 classpath 中,忽略
113-
return false;
114-
}
115-
});
116-
117-
if (!isRequired) {
118-
LOG.trace("Filtered out FIT bean '{}' - not in whitelist", beanName);
119-
filteredCount++;
120-
continue;
78+
/**
79+
* FIT 运行时检测后处理器,检测 FitRuntime Bean 初始化完成后触发 FEL Bean 注册。
80+
*/
81+
private static class FitRuntimeDetectorBeanPostProcessor
82+
implements org.springframework.beans.factory.config.BeanPostProcessor {
83+
private final ConfigurableListableBeanFactory beanFactory;
84+
private boolean registered = false;
85+
86+
FitRuntimeDetectorBeanPostProcessor(ConfigurableListableBeanFactory beanFactory) {
87+
this.beanFactory = beanFactory;
88+
}
89+
90+
@Override
91+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
92+
if (!registered && bean instanceof FitRuntime) {
93+
registered = true;
94+
registerFelBeansToSpring((FitRuntime) bean);
95+
}
96+
return bean;
97+
}
98+
99+
/**
100+
* 将 FIT 容器中符合白名单的 FEL Bean 注册到 Spring 容器。
101+
*
102+
* @param fitRuntime FIT 运行时实例
103+
*/
104+
private void registerFelBeansToSpring(FitRuntime fitRuntime) {
105+
LOG.info("Auto-registering FEL beans to Spring container (whitelist mode)");
106+
try {
107+
BeanContainer container = fitRuntime.root().container();
108+
List<BeanFactory> allFactories = container.all();
109+
LOG.debug("Found {} beans in FIT container", allFactories.size());
110+
111+
int registeredCount = 0;
112+
int skippedCount = 0;
113+
int filteredCount = 0;
114+
115+
for (BeanFactory factory : allFactories) {
116+
BeanMetadata metadata = factory.metadata();
117+
String beanName = metadata.name();
118+
Type beanType = metadata.type();
119+
String typeName = beanType.getTypeName();
120+
121+
// 检查是否在白名单中(使用字符串匹配,支持子类)
122+
boolean isRequired = REQUIRED_BEAN_TYPE_NAMES.stream().anyMatch(requiredTypeName -> {
123+
try {
124+
Class<?> actualType = Class.forName(typeName);
125+
Class<?> requiredType = Class.forName(requiredTypeName);
126+
return requiredType.isAssignableFrom(actualType);
127+
} catch (ClassNotFoundException e) {
128+
// 某些可选依赖的类可能不在 classpath 中,忽略
129+
return false;
121130
}
131+
});
122132

123-
// 避免重复注册
124-
if (beanFactory.containsSingleton(beanName) || beanFactory.containsBeanDefinition(beanName)) {
125-
LOG.debug("Skipping bean '{}' - already exists in Spring container", beanName);
126-
skippedCount++;
127-
continue;
128-
}
133+
if (!isRequired) {
134+
LOG.trace("Filtered out FIT bean '{}' - not in whitelist", beanName);
135+
filteredCount++;
136+
continue;
137+
}
129138

130-
try {
131-
if (metadata.singleton()) {
132-
Object instance = factory.get();
133-
beanFactory.registerSingleton(beanName, instance);
134-
registeredCount++;
135-
LOG.info("Registered FEL bean '{}' (type: {}) to Spring container", beanName, typeName);
136-
}
137-
} catch (Exception e) {
138-
LOG.warn("Failed to register FEL bean '{}' of type {}: {}",
139-
beanName,
140-
typeName,
141-
e.getMessage());
142-
}
139+
// 避免重复注册
140+
if (beanFactory.containsSingleton(beanName) || beanFactory.containsBeanDefinition(beanName)) {
141+
LOG.debug("Skipping bean '{}' - already exists in Spring container", beanName);
142+
skippedCount++;
143+
continue;
143144
}
144145

145-
LOG.info("FEL Bean auto-registration completed: {} registered, {} skipped, {} filtered",
146-
registeredCount,
147-
skippedCount,
148-
filteredCount);
149-
} catch (Exception e) {
150-
LOG.error("Failed to auto-register FEL beans", e);
146+
try {
147+
if (metadata.singleton()) {
148+
Object instance = factory.get();
149+
beanFactory.registerSingleton(beanName, instance);
150+
registeredCount++;
151+
LOG.info("Registered FEL bean '{}' (type: {}) to Spring container", beanName, typeName);
152+
}
153+
} catch (Exception e) {
154+
LOG.warn("Failed to register FEL bean '{}' of type {}: {}",
155+
beanName,
156+
typeName,
157+
e.getMessage());
158+
}
151159
}
160+
161+
LOG.info("FEL Bean auto-registration completed: {} registered, {} skipped, {} filtered",
162+
registeredCount,
163+
skippedCount,
164+
filteredCount);
165+
} catch (Exception e) {
166+
LOG.error("Failed to auto-register FEL beans", e);
152167
}
153-
};
168+
}
154169
}
155170
}

framework/fit/java/fit-reactor/src/main/java/modelengine/fitframework/flowable/choir/AbstractChoir.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import modelengine.fitframework.flowable.subscriber.BlockAllSubscriber;
2323
import modelengine.fitframework.flowable.subscriber.FunctionalSubscriber;
2424
import modelengine.fitframework.inspection.Nonnull;
25+
import modelengine.fitframework.inspection.Validation;
2526
import modelengine.fitframework.schedule.ThreadPoolExecutor;
2627
import modelengine.fitframework.util.ObjectUtils;
2728

@@ -130,7 +131,7 @@ public void subscribe(Subscriber<T> subscriber) {
130131
@Override
131132
public void subscribe(java.util.concurrent.Flow.Subscriber<? super T> subscriber) {
132133
if (subscriber == null) {
133-
throw new NullPointerException("Subscriber cannot be null");
134+
Validation.notNull(subscriber, "Subscriber cannot be null.");
134135
}
135136
// 使用现有的 Lambda subscribe 方法,适配 Flow Subscriber
136137
this.subscribe(

framework/fit/java/fit-reactor/src/main/java/modelengine/fitframework/flowable/solo/AbstractSolo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import modelengine.fitframework.flowable.subscriber.BlockAllSubscriber;
1818
import modelengine.fitframework.flowable.subscriber.FunctionalSubscriber;
1919
import modelengine.fitframework.inspection.Nonnull;
20+
import modelengine.fitframework.inspection.Validation;
2021
import modelengine.fitframework.util.CollectionUtils;
2122
import modelengine.fitframework.util.ObjectUtils;
2223

@@ -83,7 +84,7 @@ public void subscribe(Subscriber<T> subscriber) {
8384
@Override
8485
public void subscribe(java.util.concurrent.Flow.Subscriber<? super T> subscriber) {
8586
if (subscriber == null) {
86-
throw new NullPointerException("Subscriber cannot be null");
87+
Validation.notNull(subscriber, "Subscriber cannot be null.");
8788
}
8889
// 使用现有的 Lambda subscribe 方法,适配 Flow Subscriber
8990
this.subscribe(

0 commit comments

Comments
 (0)