views:

102

answers:

1

I have an external data source, which will return a string indicating the name of a Grails service to use.

What's the syntax to get an instance of this service programatically given the name of the service as a String?

ie. given 'GoogleWeather', give me an instance of GoogleWeatherService.

Thanks!

+2  A: 

The Grails documentation describes a way to get a service when in a servlet. This might be useful, if you can obtain the same objects in your context:

ApplicationContext ctx = (ApplicationContext)ApplicationHolder.getApplication().getMainContext();
CountryServiceInt service = (CountryServiceInt) ctx.getBean("countryService");
String str = service.sayHello(request.getParameter.("name"));    
Michael Easter
That's exactly what I'm looking for! Thanks
Thody