@Configuration vs @Component in Spring
Fast recall
Quick revision
Core answer
Understanding full @Configuration method interception and how it differs from lite @Bean methods; the container, not CGLIB alone, owns bean scope
Assuming direct @Bean method calls behave the same in full and lite configuration; proxyBeanMethods=false uses ordinary Java calls while container lookups still honor scope
Explain what happens if you call a @Bean method directly from another @Bean method in a @Configuration class versus a plain @Component class
Interview-ready guide
Interview answer
@Component registers the class itself as a bean. @Configuration also registers the class, but signals that it contains bean definitions. Its default full mode uses a generated subclass to intercept calls between @Bean methods, preserving container semantics such as a singleton reference. That statement needs a boundary: @Bean methods on ordinary components are lite configuration, and @Configuration(proxyBeanMethods=false) also disables interception. Modern configuration often avoids direct factory-method calls and asks Spring to inject dependencies as @Bean method parameters, allowing proxyBeanMethods=false.
@Configuration vs @Component in Spring
Direct Answer
@Configuration is a specialized @Component used as a source of @Bean definitions. With proxyBeanMethods=true, its @Bean method calls can be intercepted so one bean method calling another receives the container-managed instance. An ordinary @Component can also declare @Bean methods in lite mode, but direct Java calls between those methods are not intercepted. Set proxyBeanMethods=false when inter-bean method calls are not needed.
Common Mistakes & Pitfalls
- Using @Component for config classes: Freshers write a config class with @Bean methods but annotate it with @Component instead of @Configuration. The @Bean methods aren't recognized, and no beans are registered. Even if Spring somehow processes them, calling one @Bean method from another creates a new instance every time instead of returning the singleton.
- Not understanding the proxy: Freshers call a @Bean method directly in a @Configuration class and wonder why their initialization logic runs once but they expected multiple times. The CGLIB proxy caches the result. If you want a new instance on every call, use prototype scope, not repeated method calls.
- Overusing @Configuration: Making every class @Configuration when it should be @Service. @Configuration is for factory classes, not business logic. Your OrderService shouldn't be @Configuration—it should be @Service.
Check your understanding
Answer these without looking back at the article.
- What is CGLIB proxying in Spring?
- What does proxyBeanMethods=false do?
- Can you use @Bean methods in a @Component class?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.