Sobes.tech
Junior — Middle

Do @Configuration annotations have the ability to create beans in Spring?

sobes.tech AI

Answer from AI

The @Configuration annotation in Spring does not create beans by itself, but marks a class as a source of bean definitions. Inside a class annotated with @Configuration, methods annotated with @Bean are usually declared, which create and configure objects (beans) managed by the Spring container.

In other words, @Configuration is a signal to Spring that this class contains bean definitions, and the beans themselves are created by methods annotated with @Bean.

Example:

@Configuration
public class AppConfig {
    @Bean
    public MyService myService() {
        return new MyServiceImpl();
    }
}
Do @Configuration annotations have the ability to… - sobes.tech