Prev Next

Spring / Spring7 basics Interview questions

What is the purpose of the @Configuration annotation?

@Configuration marks a class as a source of bean definitions written in plain Java rather than XML. Spring processes the class specially so that any @Bean methods inside it are only ever invoked once per container, even if one @Bean method calls another directly - the container intercepts the call and returns the existing singleton instance.

@Configuration
public class AppConfig {
    @Bean
    public Clock systemClock() {
        return Clock.systemUTC();
    }
}

This behavior relies on CGLIB subclassing the configuration class at startup, which is why @Configuration classes cannot be declared final. It's the modern, type-safe replacement for the XML beans file used in older Spring applications.

Why can't a @Configuration class be declared final?
What does @Configuration replace from older Spring applications?

More Related questions...

What is Spring Framework 7? What is the minimum Java version required by Spring Framework 7? What is Jakarta EE 11 support in Spring Framework 7? What is Inversion of Control in Spring? What is Dependency Injection in Spring? What are the types of Dependency Injection in Spring? What is an ApplicationContext? What is a BeanFactory in Spring? What are Spring beans? What are the types of bean scopes in Spring? What is the purpose of the @Component annotation? What is the purpose of the @Autowired annotation? What is the purpose of the @Configuration annotation? What is the purpose of the @Bean annotation? What are stereotype annotations in Spring? What is component scanning in Spring? What is the BeanRegistrar contract introduced in Spring Framework 7? What is JSpecify in Spring Framework 7? What is the purpose of the @Value annotation? What are Spring profiles? Define a Spring Boot starter? What is auto-configuration in Spring Boot 4? What is the DispatcherServlet in Spring MVC? What is a RestController in Spring MVC? What is API Versioning support in Spring Framework 7? What are the types of HTTP message converters in Spring? Describe the RestClient in Spring Framework 7? What is the purpose of HTTP Interface clients in Spring? What are the types of Spring AOP advice? Define an Aspect in Spring AOP? What is the purpose of the @Transactional annotation? What are the types of transaction propagation in Spring? Describe AOT processing in Spring Framework 7? What is GraalVM native image support in Spring Framework 7? What is virtual thread support in Spring Framework 7? What is the purpose of a PropertySource in Spring? List the core modules of Spring Framework 7? Define a Spring MVC ViewResolver? What is the purpose of ResponseEntity? Describe the Spring Bean lifecycle basics?
Show more question and Answers...


Comments & Discussions