Recall & Review
beginner
What is the purpose of the
@Service annotation in Spring Boot?The <code>@Service</code> annotation marks a class as a service provider. It tells Spring to treat the class as a service component, which holds business logic and can be injected into other parts of the application.Click to reveal answer
beginner
How does Spring Boot treat a class annotated with <code>@Service</code>?Spring Boot automatically detects the class during component scanning and creates a singleton instance of it in the application context, making it available for dependency injection.Click to reveal answer
beginner
Can a class annotated with <code>@Service</code> be injected into a controller? How?Yes. You can inject a <code>@Service</code> class into a controller using <code>@Autowired</code> or constructor injection. This allows the controller to use the business logic defined in the service.Click to reveal answer
intermediate
Is <code>@Service</code> annotation mandatory for a service class in Spring Boot?No, but it is recommended. You can use <code>@Component</code> instead, but <code>@Service</code> makes the role of the class clearer and helps with readability and organization.Click to reveal answer
intermediate
What is the difference between
@Service and @Component annotations?<code>@Service</code> is a specialized form of <code>@Component</code> used to indicate that the class holds business logic. Functionally they behave the same, but <code>@Service</code> improves code clarity and intent.Click to reveal answer
What does the
@Service annotation do in Spring Boot?✗ Incorrect
@Service marks a class as a service component that contains business logic.How does Spring Boot find classes annotated with
@Service?✗ Incorrect
Spring Boot uses component scanning to automatically detect classes annotated with
@Service.Which annotation can be used to inject a
@Service class into another class?✗ Incorrect
@Autowired is used to inject Spring-managed beans like services into other classes.What is the default scope of a Spring bean annotated with
@Service?✗ Incorrect
By default, Spring beans including those annotated with
@Service are singletons.Which annotation is more specific for business logic classes in Spring Boot?
✗ Incorrect
@Service is a specialized annotation for business logic classes, improving clarity.Explain the role of the
@Service annotation in a Spring Boot application and how it supports dependency injection.Think about how Spring manages and uses service classes.
You got /5 concepts.
Describe the difference between
@Service and @Component annotations and why you might choose one over the other.Consider the purpose and readability of your code.
You got /5 concepts.