美文网首页Spring
@Component VS @Bean in Spring

@Component VS @Bean in Spring

作者: CuiCat | 来源:发表于2017-01-05 10:36 被阅读0次

    @Component (and @Service and @Repository) are used to auto-detect and auto-configure beans using classpath scanning. There's an implicit one-to-one mapping between the annotated class and the bean (i.e. one bean per class). Control of wiring is quite limited with this approach, since it's purely declarative.

    @Bean is used to explicitly declare a single bean, rather than letting Spring do it automatically as above. It decouples the declaration of the bean from the class definition, and lets you create and configure beans exactly how you choose.

    相关文章

      网友评论

        本文标题:@Component VS @Bean in Spring

        本文链接:https://www.haomeiwen.com/subject/hwtzvttx.html