惰性应用监听器
当我将 ApplicationListener
添加到类中时,Spring 会立即实例化该 bean(可能是为了确保该 bean 获取所有事件)。
就我而言,我有一个监听“CacheFlush”事件的bean(即我并不关心可能会错过多少事件)。
如何在 Spring 3.0 中实现惰性 ApplicationEvent
侦听器?
When I add ApplicationListener
to a class, Spring instantiates the bean eagerly (probably to make sure that the bean gets all the events).
In my case, I have a bean which listens for "CacheFlush" events (i.e. I don't really care how many I might miss).
How do I implement a lazy ApplicationEvent
listener in Spring 3.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您想要做的事情是否可以直接实现,但一个潜在的解决方案是拥有一个单独的 Observable bean 侦听缓存刷新事件,并在事件进入时通知其观察者。在初始化时让您的惰性 bean 向 Observable 注册。
I am not sure if what you want to do is possible directly, but one potential solution is to have a separate Observable bean listen for the cache flush events and notify its Observers when one comes in. Have your lazy bean register with the Observable when it is initialized.