Recall & Review
beginner
What is the role of a service class in Spring Boot?A service class contains business logic. It acts as a middle layer between controllers and repositories, handling data processing and rules before saving or returning data.Click to reveal answer
beginner
Why should business logic not be placed in controllers or repositories?
Controllers should only handle HTTP requests and responses, while repositories manage data access. Putting business logic in services keeps code organized, easier to test, and maintainable.
Click to reveal answer
beginner
How do you annotate a service class in Spring Boot?Use the @Service annotation above the class. This tells Spring to treat it as a service component and manage it as a bean.
Click to reveal answer
intermediate
What is a common pattern for calling a service from a controller?
The controller injects the service using @Autowired or constructor injection, then calls service methods to perform business logic before returning results.
Click to reveal answer
intermediate
Give an example of business logic that belongs in a service.
Calculating discounts, validating user input beyond simple format checks, or deciding if a user can perform an action based on roles are examples of business logic for services.
Click to reveal answer
What annotation marks a class as a service in Spring Boot?
✗ Incorrect
The @Service annotation marks a class as a service component in Spring Boot.
Where should business logic primarily reside in a Spring Boot app?
✗ Incorrect
Business logic belongs in the service layer to keep code organized and maintainable.
Which of these is NOT a responsibility of a service class?
✗ Incorrect
Handling HTTP requests is the controller's job, not the service's.
How does a controller typically get access to a service?
✗ Incorrect
Spring injects service beans into controllers using @Autowired or constructor injection.
Which example is a good candidate for business logic in a service?
✗ Incorrect
Deciding user permissions is business logic and belongs in the service layer.
Explain why business logic should be placed in service classes rather than controllers or repositories.
Think about keeping code organized and responsibilities clear.
You got /5 concepts.
Describe how a Spring Boot controller interacts with a service to perform business logic.
Focus on the flow from controller to service to repository.
You got /5 concepts.