在从 Spring Boot 2.0.3 更新到 2.2.4 之前,我们有一些注释,如下例所示:
import org.springframework.stereotype.Component;
@Component
public @interface Adapter {
}
在 ComponentScan 期间,使用此 Adapter 注释注释的类被拾取并添加到 Spring 上下文中。更新后有现在org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'XY' available
。
根据Spring Annotation Programming Model术语中关于 Stereotype Annotations 的一段话,我们的方法应该有效:
任何带有@Component 注解的组件都是组件扫描的候选对象。类似地,任何使用注释注释的组件本身也使用@Component 进行元注释也是组件扫描的候选对象。
我通读了 Spring Boot 2.1 和 2.2 的发行说明以及 Spring Framework 5.1 和 5.2 的发行说明,但没有发现原型注释的行为在这一点上发生了变化。
当我使用 Spring 提供的原型注释(除了我们自己的注释)来注释类时,它们会被 ComponentScan 拾取。
我也尝试@ComponentScan
像这样设置自定义过滤器
@ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION,
classes = Adapter.class))
但仍然得到NoSuchBeanDefinitionException
最后,我偶然发现了 Spring 框架中的这种“增强”,并想知道这是否是我问题的根源。
所以到目前为止没有任何效果,如果有人能指出我的方向来恢复我们自己的刻板印象注释再次起作用的原始行为,我会很高兴。提前致谢。