How to select a runtime class based on a RequestParam using Spring MVC?

1

Let's say I have the following @RestController in my code that uses Spring MVC:

@RestController
public class Exemplo {

@RequestMapping(value = "exemplo", method = RequestMethod.GET)
public InterfaceDeExemplo exemplo(@RequestParam String escolha) {
    Interface resultado;
    /* Cria uma instância por aqui. */
    return resultado;
}

}

And let's also say that I have some implementations of my Exponential Interface ImplementationA , ImplementationB and ImplementationC available in runtime and I have to choose between them from the @RequestParam String choice .

I know you could choose Factory Factory's design patterns, but I'm looking for a way to do this using dependency injection.

I checked that maybe the solution to this problem was related to Spring's @Conditional annotation, but I'm not sure how I'd get the value of the @RequestParam String choice in my class that implements the Condition interface .

    
asked by anonymous 02.06.2016 / 12:18

0 answers