Complete the code to declare a Spring bean using annotation.
@Component public class [1]Service { // service logic }
The class name should represent the service, so UserService is correct here.
Complete the code to inject a bean using Spring's dependency injection.
public class UserController { @[1] private UserService userService; }
The @Autowired annotation tells Spring to inject the bean automatically.
Fix the error in the bean declaration by completing the annotation.
@[1] public class OrderService { // service logic }
The @Service annotation is the best practice to declare a service bean in Spring.
Fill both blanks to complete the code for constructor injection in Spring.
public class PaymentController { private final PaymentService paymentService; public PaymentController([1] paymentService) { this.[2] = paymentService; } }
The constructor parameter type is PaymentService and the field assigned is paymentService.
Fill all three blanks to complete the code for a Spring configuration class defining a bean.
@Configuration public class AppConfig { @Bean public UserService [1]() { return new [2](); } @Bean public UserRepository [3]() { return new UserRepository(); } }
The method names for beans are usually camelCase like userService and userRepository. The classes are PascalCase like UserService.