Spring's autowired service?

Reflection is almost always a bad idea, and a sign of poor OO design.

Reflection is almost always a bad idea, and a sign of poor OO design. To avoid your if clause (which, IMHO, and unless it is repeated too many times, is maintainable, readable, easy to understand, test and debug), you could store your two services instances in a map: Map services = new HashMap(); services. Put("a", aService); services.

Put("b", bService); //... String checkList = request. GetParameter("listType"); ServiceInterface service = this.services. Get(checkList); modelMap.

AddAttribute("list", service.getList()); If this is repeated in several classes, put this map into a separate Spring bean called ServiceInterfaceFactory, and containing a method ServiceInterface create(String checkList).

Thanks JB... I'm gonna use map for now... – rrkwells Aug 7 at 0:11.

If possible, make both services implement the same interface and write a factory method that instantiates the one you need.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions