@ComponentScan
使用 @Configuration
和 @Component
创建 bean。交换时,这两个注释都可以正常工作。那有什么区别呢?
最佳答案
@Configuration Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime
@Component Indicates that an annotated class is a "component". Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning.
@Configuration is meta-annotated with @Component, therefore @Configuration classes are candidates for component scanning
你可以在这里看到更多:
@Configuration 也是@Component,但@Component 不能像@Configuration 那样工作。
关于spring - Spring中的@Configuration和@Component有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39174669/