What happens when @Lazy annotation is applied to a singleton bean in Spring?
Answer: A
@Lazy defers bean instantiation until it's first requested, overriding the default eager initialization behavior of singleton beans.
Q.942Medium
Which annotation is used to provide external configuration properties to Spring beans in the 2024 Spring Boot version?
Answer: D
@PropertySource loads properties from files, @ConfigurationProperties binds properties to bean properties, and @Value injects individual values. All are used for configuration.
Q.943Hard
What is the primary difference between BeanFactory and ApplicationContext in Spring?
Answer: A
ApplicationContext extends BeanFactory and adds features like event publishing, message resource handling, and easier AOP integration.
Q.944Hard
In a complex Spring application, when would you prefer to use ObjectFactory<T> over direct bean injection?
Answer: D
ObjectFactory enables lazy initialization, provides new instances for prototype beans, and can help resolve circular dependencies through deferred access.
Q.945Medium
What is the significance of the @Qualifier annotation when used alongside @Autowired in Spring?
Answer: B
@Qualifier resolves ambiguity in autowiring by specifying the exact bean name or custom qualifier to inject when multiple beans of the same type exist.
Advertisement
Q.946Hard
Consider a Spring application where you need different bean implementations based on the deployment environment. Which approach is most suitable?
Answer: D
@Profile is for environment-based activation, @Conditional for custom logic, and @ConditionalOnProperty for property-driven bean registration. Choice depends on specific requirements.
Q.947Easy
What does the @Scope annotation with value 'prototype' mean in Spring Framework?
Answer: A
Prototype scope creates a new bean instance each time it's requested, unlike singleton which creates only one instance for the entire application.
Q.948Medium
In Spring Framework 6.0, what is the role of the @EnableAutoConfiguration annotation in Spring Boot?
Answer: D
@EnableAutoConfiguration (or @SpringBootApplication which includes it) auto-configures Spring beans based on jar dependencies on the classpath.
Q.949Medium
What is the purpose of using @Bean method parameters in Spring @Configuration classes?
Answer: D
Method parameters in @Bean methods allow Spring to inject dependent beans and establish bean relationships, enabling dependency injection at bean creation time.
Q.950Easy
Which of the following best describes the purpose of Spring's Stereotype annotations (@Service, @Repository)?
Answer: B
Stereotype annotations (@Service, @Repository, @Controller) enable classpath component scanning and convey the architectural role of the class.
Q.951Hard
In a multi-threaded Spring application with singleton beans, what thread-safety consideration must be kept in mind?
Answer: B
Spring doesn't enforce thread-safety for singleton beans. Developers must implement thread-safe code, use immutable objects, or utilize synchronization where necessary.