When would you use request-scoped beans in a Spring web application?
ATo store request-specific data that should not be shared across different HTTP requests
BTo reduce memory consumption by reusing beans across requests
CTo improve application performance significantly
DTo simplify configuration by avoiding singleton bean management
Correct Answer:
A. To store request-specific data that should not be shared across different HTTP requests
EXPLANATION
Request-scoped beans are instantiated per HTTP request and destroyed after request completion, ideal for storing user-specific or request-specific information.
What does the @EnableCaching annotation enable in a Spring application?
ADeclarative caching support using @Cacheable, @CacheEvict, and similar annotations
BAutomatic HTTP response caching by the server
CDatabase query result caching with Redis integration
DBrowser-level caching of static resources
Correct Answer:
A. Declarative caching support using @Cacheable, @CacheEvict, and similar annotations
EXPLANATION
@EnableCaching activates Spring's caching infrastructure, allowing method-level caching through annotations like @Cacheable to store and retrieve results.
What is the significance of the @ConfigurationProperties annotation in Spring Boot?
AIt binds external configuration properties to Java objects with type-safe access
BIt encrypts sensitive configuration values automatically
CIt validates configuration file syntax during application startup
DIt generates configuration files from Java classes
Correct Answer:
A. It binds external configuration properties to Java objects with type-safe access
EXPLANATION
@ConfigurationProperties enables binding of external properties (from application.properties/yml) to POJO classes, providing type safety and validation.
What does the @Transactional annotation do in Spring?
AManages database transactions, handling commit and rollback automatically
BEncrypts data being transmitted across the network
CLogs all database operations performed by the method
DValidates input parameters before method execution
Correct Answer:
A. Manages database transactions, handling commit and rollback automatically
EXPLANATION
@Transactional delegates transaction management to Spring, automatically committing on success and rolling back on exceptions, following ACID principles.
In Spring AOP, what does the term 'Join Point' refer to?
AA specific point during program execution where an aspect can be applied
BThe code written in an aspect to handle cross-cutting concerns
CA method that connects multiple beans together
DThe configuration file that defines AOP rules
Correct Answer:
A. A specific point during program execution where an aspect can be applied
EXPLANATION
A Join Point is a candidate point in program execution (method call, exception throw) where advice can be applied. Pointcuts select specific Join Points.
What is the function of the BeanFactory interface in Spring?
ATo create and manage bean instances with lazy initialization capability
BTo provide enterprise features like AOP and transaction management
CTo store all bean metadata in an internal registry
DTo enforce naming conventions for beans
Correct Answer:
A. To create and manage bean instances with lazy initialization capability
EXPLANATION
BeanFactory is the core interface for accessing beans, providing lazy initialization. ApplicationContext extends BeanFactory with additional enterprise features.