How does Spring handle circular dependency between two beans?
Answer: A
Spring can resolve circular dependencies when at least one injection is done via setter method rather than constructor, allowing lazy initialization.
Q.922Medium
What is the function of the BeanFactory interface in Spring?
Answer: A
BeanFactory is the core interface for accessing beans, providing lazy initialization. ApplicationContext extends BeanFactory with additional enterprise features.
Q.923Medium
In Spring AOP, what does the term 'Join Point' refer to?
Answer: A
A Join Point is a candidate point in program execution (method call, exception throw) where advice can be applied. Pointcuts select specific Join Points.
Q.924Medium
What does the @Transactional annotation do in Spring?
Answer: A
@Transactional delegates transaction management to Spring, automatically committing on success and rolling back on exceptions, following ACID principles.
Q.925Hard
An enterprise application requires different bean implementations based on runtime conditions. Which Spring feature is most suitable?
Answer: D
@Conditional provides fine-grained control, @Profile handles environment-specific beans, and factory beans offer explicit creation logic. Choice depends on use case requirements.
Advertisement
Q.926Medium
What is the significance of the @ConfigurationProperties annotation in Spring Boot?
Answer: A
@ConfigurationProperties enables binding of external properties (from application.properties/yml) to POJO classes, providing type safety and validation.
Q.927Hard
Consider a Spring application where method execution time tracking is required across multiple methods. Which approach is most appropriate?
Answer: A
Spring AOP with a custom aspect provides centralized, reusable cross-cutting concern implementation without code duplication in individual methods.
Q.928Easy
What is the default behavior of Spring when multiple beans of the same type are available for autowiring?
Answer: A
Spring raises NoUniqueBeanDefinitionException when ambiguity exists. Use @Primary or @Qualifier to resolve the ambiguity.
Q.929Hard
In Spring framework, what is the purpose of FactoryBean interface?
Answer: A
FactoryBean allows creating beans with sophisticated initialization logic through getObject() method, useful for complex object creation.
Q.930Medium
What does the @EnableCaching annotation enable in a Spring application?
Answer: A
@EnableCaching activates Spring's caching infrastructure, allowing method-level caching through annotations like @Cacheable to store and retrieve results.
Q.931Medium
When would you use request-scoped beans in a Spring web application?
Answer: A
Request-scoped beans are instantiated per HTTP request and destroyed after request completion, ideal for storing user-specific or request-specific information.
Q.932Medium
What is the difference between constructor injection and setter injection in Spring?
Answer: A
Constructor injection enforces required dependencies and creates immutable objects; setter injection allows optional dependencies and partial initialization.
Q.933Easy
Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework 6.0?
Answer: D
@Component, @Service, @Repository, and @Controller are all stereotype annotations that mark classes as Spring Beans. @Bean is used for method-level bean definition.
Q.934Easy
What is the primary purpose of the ApplicationContext in Spring Framework?
Answer: B
ApplicationContext is the core container that instantiates, configures, and manages beans. It also resolves dependencies and manages bean lifecycle.
Q.935Easy
Which of the following is NOT a valid Spring Bean scope in Spring Framework 2024?
Answer: D
Spring supports singleton, prototype, request, session, application, and websocket scopes. 'Eternal' is not a valid scope in Spring Framework.
Q.936Medium
In Spring Framework, what does the @Autowired annotation do when autowiring candidates are ambiguous?
Answer: D
When multiple beans match the injection point, Spring throws an exception unless @Primary is used to indicate the preferred bean or @Qualifier specifies which bean to inject.
Q.937Medium
What is the difference between @Bean and @Component annotations in Spring?
Answer: B
@Component is applied to classes making them beans automatically. @Bean is applied to methods in @Configuration classes, giving explicit control over bean creation.
Q.938Medium
Consider a scenario where a Spring application needs to initialize a database connection pool at startup. Which method should be used?
Answer: D
Spring provides multiple mechanisms for initialization: @PostConstruct, InitializingBean interface, and initMethod in @Bean definition. All are equally valid.
Q.939Medium
What is the role of Spring's PropertyPlaceholderConfigurer in application configuration?
Answer: B
PropertyPlaceholderConfigurer (or @PropertySource in modern Spring) enables externalization of configuration by replacing ${property.name} placeholders with actual values from properties files.
Q.940Medium
In Spring Framework, which interface represents a factory pattern implementation for creating objects?
Answer: D
BeanFactory is the basic container, ObjectFactory is for lazy bean retrieval, and FactoryBean allows custom bean creation logic. All represent factory patterns in Spring.