I have an interface as following:
public interface Solver {
void execute(final String definition);
}
I have several solver implementations. For example:
@Qualifier("naive")
@Service
public class NaiveSolver implements Solver {
@Override
public void execute(final String definition) {
}
}
@Qualifier("optimal")
@Service
public class OptimalSolver implements Solver {
@Override
public void execute(final String definition) {
}
}
Now, in my database I have the data for these solvers as following:
type: textual - examples: simple, naive
definition: textual
When fetching this data, I need to map the type
column to the actual service instance, so it can solve the provided definition
.
So, my question boils down to this: how can I, given a type
string, get the instance of the corresponding Solver
service instance of which the qualifier is equal to that type
? I believe that @Autowired
cannot be used here, as I need to find beans dynamically at runtime.