Can Spring autowire variables of a class based on the Qualifier which was used to autowire the class enclosing those variables?
Say, I have a common ToolsSet class
public class ToolsSet {
@AutoWired Drill drill;
@AutoWired Hammer hammer;
}
@Qualifier("IndustrialTools")
public class IndustrialHammer implements Hammer {}
@Qualifier("IndustrialTools")
public class IndustrialDrill implements Drill {}
@Qualifier("HomeTools")
public class HomeHammer implements Hammer{}
@Qualifier("HomeTools")
public class HomeDrill implements Drill{}
Different jobs need different toolsets,
public class JobA {
@AutoWired
@Qualifier("HomeTools")
ToolsSet toolsSet;
}
public class JobB {
@AutoWired
@Qualifier("IndustrialTools")
ToolsSet toolsSet;
}
Is it possible to autowire the variables of the ToolsSet class based on the Qualifier used to autowire the Jobs class?
Edit: I know that I can always write a @Configuration class, and define beans for different qualifiers. I just want to skip the configuration class. What I would like to have is to use the Qualifier once, in the Job class and automagically autowire the Drill and Hammer classes using the same qualifier which was used to autowire the ToolsSet class.