Grails - 将SessionListener注册为Spring Bean [英] Grails - Register SessionListener as a Spring Bean

查看:121
本文介绍了Grails - 将SessionListener注册为Spring Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Session Listener(实现HttpSessionListener)注册为Spring Bean?
我的工作实现将监听器添加到BootStrap.groovy中的servlet上下文中。

Is it possible to register a Session Listener (implementation of HttpSessionListener) as a Spring Bean. My working implementation adds the listener to the servlet contexts in BootStrap.groovy

def init = { servletContext ->
      servletContext.addListener(userLoginSessionListener)
}

但这会导致我的集成测试使用UnsupportedOperationException失败(将为此创建另一个问题)

but this causes my integration tests to fail with an UnsupportedOperationException (will create another question for this)

现在我在resources.groovy中有以下内容:

Now I have the following in resources.groovy

userLoginSessionListener(UserLoginSessionListener)

但现在我的sessionCreated和sessionDestroyed方法不再被触发。

but now my sessionCreated and sessionDestroyed methods are no longer being triggered.

推荐答案

不得不走下老式的路线。
删除了bean定义和BootStrap.groovy配置,并通过_Events.groovy中的eventWebXmlEnd处理程序添加了监听器,这对我们的集成测试非常有效。

Had to go down the old fashioned route. Removed the bean definition and BootStrap.groovy config and added the listener via the eventWebXmlEnd handler in _Events.groovy which played well with our integration tests.

<listener>
       <listener-class>com.example.UserLoginSessionListener</listener-class>
</listener>

这篇关于Grails - 将SessionListener注册为Spring Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆