mercredi 15 avril 2015

Spring inject service according to parameter

I am learning struts+spring, I have a struts action class:



public class Testction{
private String type;

private TestService service;

//...ignore getters and setters here
public String test(){
// action method
}
}


Can Spring inject different TestService implementation according to type parameter ? TestService is just a interface.


If this is possible, where shoud I put @service annotation? on interface or implementation class ?


If that is impossible or hard to go, how to do it in code ?


Spring helps us a lot, but also can make me confused when I want to think deeper.Take above code as example, "type" seems injected by struts, and "service" is injected by spring if TestService is annotated by @service.


so complex...


Aucun commentaire:

Enregistrer un commentaire