What is the difference between @Configuration and @Component in Spring?

后端 未结 5 1128
感动是毒
感动是毒 2020-12-05 00:00

@ComponentScan creates beans using both @Configuration and @Component. Both these annotations work fine when swapped. What is the diff

5条回答
  •  时光取名叫无心
    2020-12-05 00:24

    Apart from the differences highlighted by reos.

    The reason why @Configuration cannot be replaced by @Component is as below:

    The difference is in how the inter bean dependency is handled. Refer the link for a detailed explanation with example: Difference between Configuration and Component

提交回复
热议问题