Complete the code to mark the class as a Spring component.
@[1] public class MyService { // service methods }
The @Component annotation tells Spring to treat this class as a component and manage its lifecycle.
Complete the code to inject the component into another class using Spring's annotation.
public class MyController { @[1] private MyService myService; }
The @Autowired annotation tells Spring to inject the component automatically.
Fix the error in the code by completing the annotation to register the class as a Spring component.
@[1] public class DataRepository { public void save() { // save data } }
The @Repository annotation is a specialized form of @Component for data access classes.
Fill both blanks to create a Spring component and inject it into another class.
@[1] public class NotificationService { public void notifyUser() { // notify logic } } public class UserController { @[2] private NotificationService notificationService; }
The @Component annotation registers the class as a Spring bean, and @Autowired injects it where needed.
Fill all three blanks to define a Spring component with a method and inject it properly.
@[1] public class EmailSender { public void sendEmail() { // send email logic } } public class NotificationController { @[2] private EmailSender [3]; }
@Component registers the class as a Spring bean, @Autowired injects it, and emailSender is the variable name used for the injected instance.