【发布时间】:2015-05-28 04:43:49
【问题描述】:
我已经使用 @Lookup 注释实现了一个 Spring bean。 (这个帖子很有帮助:How to use spring @Lookup annotation?)
我随后注意到一种奇怪的行为,我不确定是设计使然还是我自己的误解。 Spring 将在使用 @Service、@Component 等注释的 ComponentScan-ed bean 中实现 @Lookup 方法,但不会在 @Configuration 类 (Application.java) 中定义的 @Bean 中实现这样的方法。
这不是什么大问题,因为我可以从配置中删除@Bean 定义,而是直接注释它的类;但我想知道这种行为是否记录在某处,还是我执行不正确?
@Bean
public Service getService() {
// ServiceImpl has a @Lookup method,
// but Spring does not implement it unless the class itself is annotated.
return new ServiceImpl();
}
【问题讨论】:
标签: java spring annotations spring-annotations