You're right in that the autowiring is all done once up front (point 3). You wouldn't be able to achieve what you want using fields annotated @Autowired
and @Qualifier
- as these fields would always reference the same bean instance.
You may be better to ask Spring for the particular service bean by name - based on the path variable. You could do it within a single controller instance. For example:
@Cotroller
@RequestMapping(value="/generate/{path}")
public class TestController {
@Autowired
private ApplicationContext applicationContext;
@RequestMapping(method = RequestMethod.POST)
public String someHandlerMethod(@PathVariable String path) {
IService service = (IService) applicationContext.getBean(path + "Service");
IUserInput userInput = (IUserInput) applicationContext.getBean(path + "UserInput");
// Logic using path specific IService and IUserInput
}
}