Complete the code to declare a Spring bean using annotation.
@Configuration public class AppConfig { @Bean public MyService [1]() { return new MyService(); } }
The method name myService is used as the bean name by default in Spring when using @Bean.
Complete the code to inject a bean into a Spring component using annotation.
@Component public class UserController { private final UserService userService; public UserController([1] UserService userService) { this.userService = userService; } }
The @Autowired annotation tells Spring to inject the bean automatically into the constructor.
Fix the error in the bean scope declaration.
@Bean @Scope([1]) public SessionBean sessionBean() { return new SessionBean(); }
The "session" scope defines a bean that is created once per HTTP session in Spring web applications.
Fill both blanks to create a bean with a custom name and prototype scope.
@Bean(name = "[1]") @Scope("[2]") public ProductService [3]() { return new ProductService(); }
The bean is named customProductService, has prototype scope, and the method name is productService.
Fill all three blanks to define a bean with lazy initialization, singleton scope, and a qualifier.
@Bean @Lazy([1]) @Scope("[2]") @Qualifier("[3]") public NotificationService notificationService() { return new NotificationService(); }
The bean is lazily initialized (true), has singleton scope, and is qualified with emailService.