Servlets 从Grails引导中的servletContext访问HttpSession

Servlets 从Grails引导中的servletContext访问HttpSession,servlets,grails,bootstrapping,httpsession,Servlets,Grails,Bootstrapping,Httpsession,我们可以通过servletContext(或grailsApplication)访问Grails引导中的HttpSession吗?当用户登录到应用程序时,我在会话中存储了一些信息,并在插入前在动态方法中使用它们。但我不知道如何在会话中检索这些信息。 这是我的引导代码: class BootStrap { def grailsApplication def init = { servletContext -> grailsApplication.getArte

我们可以通过servletContext(或grailsApplication)访问Grails引导中的HttpSession吗?当用户登录到应用程序时,我在会话中存储了一些信息,并在插入前在动态方法中使用它们。但我不知道如何在会话中检索这些信息。
这是我的引导代码:

class BootStrap {
    def grailsApplication
    def init = { servletContext ->
        grailsApplication.getArtefacts("Domain").each { org.codehaus.groovy.grails.commons.GrailsDomainClass gc ->
            gc.metaClass.beforeInsert = {
                // Do something here with information stored in session
            }

            gc.metaClass.beforeUpdate = {
                               // Do something here with information stored in session
                    }
        }
    }
    def destroy = {
    }
}

非常感谢

不,因为servlet上下文有多个会话。会话是每个用户的,而上下文是全局的。所以范围不匹配

您可以使用一个侦听会话创建和会话删除的
HttpSessionListener
。我想您可以通过某种方式访问在服务器关闭后序列化到磁盘的会话,但这需要您干扰本机tomcat实现(可能是某种阀门)