gpt4 book ai didi

spring - Spring中的@Configuration和@Component有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 13:51:56 25 4
gpt4 key购买 nike

@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

你可以在这里看到更多:

http://docs.spring.io/spring-framework/docs/4.0.4.RELEASE/javadoc-api/org/springframework/context/annotation/Configuration.html

@Configuration 也是@Component,但@Component 不能像@Configuration 那样工作。

关于spring - Spring中的@Configuration和@Component有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39174669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com