【问题标题】:Application context from a Grails plugin?来自 Grails 插件的应用程序上下文?
【发布时间】:2012-05-23 05:14:51
【问题描述】:

我正在开发一个插件并尝试尽可能地正确解耦。如何获取包含我的插件的 grails-app 的应用程序上下文?我有一个 doWithWebDescriptor,其中包含一个 servlet,该 servlet 包含在主 grails-app 上下文中:

/MainApp/servlet-url-pattern

我想在插件的 GSP 中引用它。什么是合适的方式?

【问题讨论】:

    标签: grails grails-plugin


    【解决方案1】:

    这里我可能错了,但我认为 doWithWebDescriptor 是用来生成 web.xml 文件的。该文件是启动应用程序所必需的。如果您的应用程序未启动,则您还不能拥有 spring 上下文。

    【讨论】:

      【解决方案2】:

      将此行添加到您的bootstrap.groovy 中的init

      ApplicationContext appContext = (ApplicationContext)
      servletContext.getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT);
      

      您还可以在使用应用程序上下文的类中从引导程序中设置上下文。

      YourClassName.setContext(appContext);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-08
        • 1970-01-01
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-29
        相关资源
        最近更新 更多