`
casephoen
  • 浏览: 19372 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

get a resource from the servletContext or applicat

阅读更多

To get the ApplicationContext, have your service implement ApplicationContextAware and declare an 'applicationContext' field. Then from within your service:

 

def resource = applicationContext.getResource("foo")

Accessing the Servlet Context:

import org.codehaus.groovy.grails.commons.ApplicationHolder

def applicationContext = ApplicationHolder.getApplication().getParentContext()

def servletContext = ApplicationHolder.getApplication().getParentContext().getServletContext()

Alternate way of accessing the Servlet Context:

 

import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH

def servletContext = SCH.servletContext

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics