InterviewSolution
| 1. |
What is @Autowired annotation? How is @Qualifier used with it? |
|
Answer» @Autowired ANNOTATION is used to AUTOWIRE i.e. inject dependent bean on the constructor, setter method or a field/property. When @Autowired is used on dependency, the application context searches for a matching dependency and provides as required. This helps us to avoid writing EXPLICIT injection logic. However, by default, all dependencies that are Autowired are required. So, in scenarios where a required dependency is not available or if there is conflict; it results in an exception like NoUniqueBeanDefinitionException. There are a few options available to turn off the default behavior:
@Autowired (required=false) private Contract contractBean;
@Qualifier ("design") private Contract contractBean; |
|