用@Component("implForRq1")
和声明实现@Component("implForRq2")
然后将它们都注入并使用:
class Runner {
@Autowired @Qualifier("implForRq1")
private MyInterface runnerOfRq1;
@Autowired @Qualifier("implForRq2")
private MyInterface runnerOfRq2;
void run(int rq) {
switch (rq) {
case 1: runnerOfRq1.run();
case 2: runnerOfRq2.run();
...
}
}
}
...
@Autowired
Runner runner;
void run(int rq) {
runner.run(rq);
}