【问题标题】:How to access the ServletContext in resources.groovy for Grails 3?如何访问 Grails 3 的 resources.groovy 中的 ServletContext?
【发布时间】:2016-08-08 21:03:25
【问题描述】:

我需要为 spring 定义几个 bean 并配置我需要访问 ServletContext 的 bean。以前在 Grails 2.x 中,我们有类似

的代码
beans = {
    ...
    dataProvider(DataProvider) {
        def context = ServletContextHolder.getServletContext()
        // use context to configure this bean
    }
    ...
}

但是在 grails 3.x(具体来说是 3.1.10)中,上下文变量始终为空。如果除了resources.groovy 文件之外还有其他地方可以完成此操作,那也没关系。

【问题讨论】:

    标签: spring servlets grails


    【解决方案1】:

    我会用

    def context = application.mainContext.servletContext
    

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 2016-12-03
      相关资源
      最近更新 更多