Pivotal Knowledge Base


Spring Framework: How To Customize Auto-Wiring using User Defined Classes


 Product  Version
 Spring  All


This article provides information on customizing auto wiring for Spring Framework using unrelated (not by type or name) user-defined classes.


You can customize Auto wiring for your classes by specifying a qualifier. For example, you may use the class MyProvider below. Notice that @Qualifier should co-exist with the @Component Annotation so that the MyProvider class could be created.

public class MyProvider {
// Implementation omitted

If, for instance, you want a Spring Controller to have a property that will hold a list of Objects with classes you qualified as content provider, use the @Autowire annotation from your controller on one of your setters. You can use the @Qualifer to control Auto wiring:

public class MyController {
.... @Autowired
public void setProviders(@Qualifier("contentprovider") List< Object > providers) {

Additional Information

For more information on auto wiring with qualifiers, refer to 4.9.3 Fine-tuning annotation-based auto wiring with qualifiers.


Powered by Zendesk