Bird
0
0

Consider the following Spring Boot class:

medium📝 component behavior Q13 of 15
Spring Boot - Spring Annotations
Consider the following Spring Boot class:
@Service
public class UserService {
    public String getUser() {
        return "Alice";
    }
}
What is the role of this class in the application?
AContains business logic related to users
BAccesses the database to retrieve user data
CGeneral Spring bean without specific role
DHandles HTTP requests and responses
Step-by-Step Solution
Solution:
  1. Step 1: Identify the annotation and its meaning

    The class is annotated with @Service, which is used for business logic components in Spring.
  2. Step 2: Understand the method and class purpose

    The method getUser() returns a user name, indicating business logic rather than database access or HTTP handling.
  3. Final Answer:

    Contains business logic related to users -> Option A
  4. Quick Check:

    @Service = business logic class [OK]
Quick Trick: @Service means business logic, not web or data access [OK]
Common Mistakes:
  • Thinking @Service accesses the database directly
  • Confusing @Service with @Controller
  • Assuming @Service is a generic bean without role

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes