I have the following classes:
public interface MyInterface{}
public class MyImpl1 implements MyInterface{}
public class MyImpl2 implements MyInterface{}
p
Declare implementations with @Component("implForRq1") and @Component("implForRq2")
Then inject them both and use:
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);
}