beginnerIoC Container & Dependency Injection

What's the difference between `@Component`, `@Bean`, and `@Configuration`?

`@Component` is a class-level annotation that tells component scanning to register that class itself as a bean. `@Bean` is a method-level annotation used inside a `@Configuration` class, for when you need to construct a bean yourself (e.g. a third-party class you don't own, or one needing custom setup logic) rather than annotate the class directly. `@Configuration` marks a class as a source of `@Bean` definitions and ensures those methods are CGLIB-proxied so calling one `@Bean` method from another still returns the same singleton instance.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is the default bean scope in Spring, and when would you use `prototype` instead?← Back to all Spring Boot questions