我需要找到所有出现的 @CustomAnnotation
(理想情况下任何目标)在 Spring(启动)初始化期间的某个地方 - 它可以是类似 ApplicationListener<ContextRefreshedEvent>
的事件或ApplicationContextAware
.
ClassPathScanningCandidateComponentProvider
不会为我做这件事,因为它会在加载之前扫描类上的注释(它读取元数据)。
我该怎么做?
最佳答案
我试图继续使用纯 Spring (或引导)解决方案,但我不得不回到我的老 friend - Reflection(使用 Guava )。
为了使工作尽可能无缝,我使用了:https://github.com/ronmamo/reflections
通过 ApplicationListener<ContextRefreshedEvent>
调用电话(如上面的 github 链接示例) .
很容易解决我的问题,但如果存在的话,我对纯 Spring 解决方案持开放态度(Guava 是一个额外的依赖项,也许 Spring 已经默认附带了一些东西?)。
关于java - 在 spring(启动)启动时扫描使用自定义 @Annotation 注释的任意目标(TYPE、METHOD、FIELD),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59225792/