0
0
Spring Bootframework~5 mins

Business logic in services in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@Controller
B@Service
C@Repository
D@ComponentScan
Where should business logic primarily reside in a Spring Boot app?
AIn the repository
BIn the controller
CIn the service layer
DIn the application.properties file
Which of these is NOT a responsibility of a service class?
AHandling HTTP requests
BApplying business rules
CCalling repositories
DProcessing data
How does a controller typically get access to a service?
ABy using @Autowired or constructor injection
BBy creating a new instance with 'new'
CBy calling static methods
DBy reading from a config file
Which example is a good candidate for business logic in a service?
ADefining database schema
BMapping a URL to a method
CSaving data to the database
DChecking if a user is allowed to access a feature
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.