是否可以获取所有已注册到@ComponentScan 的包的列表? 我需要知道在我的 Spring Boot 应用程序中注册了哪些(root?)包...
最佳答案
可能的解决方案 - Scanning Java annotations at runtime
使用org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
应用程序接口(interface)
A component provider that scans the classpath from a base package. It then applies exclude and include filters to the resulting classes to find candidates.
ClassPathScanningCandidateComponentProvider scanner =
new ClassPathScanningCandidateComponentProvider(<DO_YOU_WANT_TO_USE_DEFAULT_FILTER>);
scanner.addIncludeFilter(new AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class));
for (BeanDefinition bd : scanner.findCandidateComponents(<TYPE_YOUR_BASE_PACKAGE_HERE>))
System.out.println(bd.getBeanClassName());
关于java - Spring - 是否有可能获取所有包,并在@ComponentScan 中注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28014891/