我有一个外部数据源,它将返回一个字符串,指出要使用的Grails服务的名称。如何以编程方式获取Grails服务的实例?
以编程方式获得服务实例的语法是什么语法?
即。给定'GoogleWeather',给我一个GoogleWeatherService的实例。
谢谢!
我有一个外部数据源,它将返回一个字符串,指出要使用的Grails服务的名称。如何以编程方式获取Grails服务的实例?
以编程方式获得服务实例的语法是什么语法?
即。给定'GoogleWeather',给我一个GoogleWeatherService的实例。
谢谢!
The Grails documentation描述了一种在servlet中获得服务的方法。这可能是有用的,如果你能得到你的背景下,相同的对象:
ApplicationContext ctx = (ApplicationContext)ApplicationHolder.getApplication().getMainContext();
CountryServiceInt service = (CountryServiceInt) ctx.getBean("countryService");
String str = service.sayHello(request.getParameter.("name"));
由于ApplicationHolder已被弃用,这是另一种方式来获得的ApplicationContext:
ApplicationContext ctx = Holders.grailsApplication.mainContext
这就是我到底是什么寻找!谢谢 – Thody 2010-02-16 22:04:00