Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework 6.0?
A@Component
B@Bean
C@Service
DAll of the above
Correct Answer:
D. All of the above
EXPLANATION
@Component, @Service, @Repository, and @Controller are all stereotype annotations that mark classes as Spring Beans. @Bean is used for method-level bean definition.
C@Component requires manual bean registration, while @Service auto-registers
DThere is no functional difference; they are completely interchangeable
Correct Answer:
A. @Component is generic, while @Service is semantically used for business logic classes
EXPLANATION
@Component is a generic stereotype, while @Service is a specialized annotation indicating the class contains business logic, improving code readability.
Which of the following correctly describes the lifecycle of a singleton-scoped Spring bean?
ACreated once per HTTP request and destroyed after the request completes
BCreated once when the ApplicationContext is initialized and persists throughout the application lifetime
CCreated every time it is referenced and destroyed immediately after use
DCreated in a separate thread context and shared across multiple threads
Correct Answer:
B. Created once when the ApplicationContext is initialized and persists throughout the application lifetime
EXPLANATION
Singleton beans are instantiated once per Spring container and reused for the application's lifetime, making them memory-efficient for stateless objects.