Hi Srinivas,
The example is clear, thanks.
You're correct that JavaConfig does not support @Qualifier as you're trying to use it. That will come, but in the meantime, you're not out of luck.
You can autowire by name by simply providing the bean name as the value attribute to the @Qualifier annotation.
Drawing from your example:
Code:
@Configuration
@AnnotationDrivenConfig
public class MyAppConfig {
@Bean
public DataProvider xmlDataProvider() {
return new XMLDataProvider();
}
@Bean
public DataProvider dbDataProvider() {
return new DBDataProvider();
}
}
You can actually use the xmlDataProvider and dbDataProvider bean names as qualifiers:
Code:
public class MyBusinessBean {
@Autowired
@Qualifier("xmlDataProvider")
DataProvider dataProvider;
public doBusiness() {
dataProvider.getBusinessData();
}
}
Alternatively, this can be done more concisely using the JSR-250 @Resource annotation:
Code:
public class MyBusinessBean {
@Resource("xmlDataProvider")
DataProvider dataProvider;
public doBusiness() {
dataProvider.getBusinessData();
}
}
Hope that helps.