Middle+
What are configuration beans (@Configuration) used for?
sobes.tech AI
Answer from AI
In the Spring Framework, the @Configuration annotation is used to denote a class that contains bean definitions — components managed by the Spring container.
Configurable beans allow:
- Grouping settings and bean definitions in one place.
- Using Java code for application configuration instead of XML.
- Defining methods with the
@Beanannotation that return objects created and managed by Spring.
Example:
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
Thus, @Configuration helps centralize and structure application setup, providing convenient management of dependencies and component lifecycle.