midSpring
What is the difference between @Bean and @Component?
Updated May 17, 2026
Short answer
@Component is class-level annotation; @Bean is method-level bean definition.
Deep explanation
@Component is used for auto-detection via component scanning. @Bean is explicitly declared inside @Configuration classes for third-party or complex bean creation.
Real-world example
Using @Bean for external library objects like RestTemplate.
Common mistakes
- Using @Component for classes you don't control.
Follow-up questions
- When to prefer @Bean?
- What is component scanning?