fix @Import duplicate registration and add JavaFX demo test
- Fix @Import processing to skip already registered beans from package scan - Add extractBeanName helper method for bean name extraction - Set MainController to PROTOTYPE scope to avoid eager initialization - Add FxDemoTest for testing JavaFX components without GUI - Test configuration beans, services, and dependency injection - All JavaFX demo components tested successfully Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -132,9 +132,20 @@ public class TimiInject {
|
||||
throw new InjectException("Failed to instantiate module: " + importClass.getName(), e);
|
||||
}
|
||||
} else {
|
||||
scanner.processClass(importClass);
|
||||
log.debug("Imported configuration: {}", importClass.getName());
|
||||
// 检查是否已经通过包扫描注册
|
||||
String beanName = extractBeanName(importClass);
|
||||
if (!context.containsBean(beanName)) {
|
||||
scanner.processClass(importClass);
|
||||
log.debug("Imported configuration: {}", importClass.getName());
|
||||
} else {
|
||||
log.debug("Skip importing already registered class: {}", importClass.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String extractBeanName(Class<?> clazz) {
|
||||
String simpleName = clazz.getSimpleName();
|
||||
return Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user