【问题标题】:Is it possible to implement my own conversation scope?是否可以实现我自己的对话范围?
【发布时间】:2014-06-23 00:34:44
【问题描述】:

我正在使用 Spring-MVC,我需要一种 bean 范围,例如 Conversation Scope。我知道 Spring Web Flow,但我不喜欢它,因为它让我感觉像是用 XML 编程。

所以我想用以下功能实现我自己的对话范围:

  1. 超时。当指定的时间过去后,这个 cope 应该被自动销毁。
  2. 我也可以手动销毁这个范围。比如调用myscope.destroy()方法。

我该如何实现它?

【问题讨论】:

  • 问题是?
  • @SergeBallesta 我想自己实现一个对话范围
  • 所以你应该:首先阅读 Spring Reference Manual 的相关部分,然后在 spring custom scope tutorial 上阅读第二个 google。我做的第一个答案是来自 JavaBeat 的Custom Scope for Spring Beans 似乎与您的问题有关。

标签: spring spring-mvc servlets


【解决方案1】:

是否可以实现我自己的对话范围?

答案:是的

它被称为“自定义范围”。因此,您需要有一个实现org.springframework.beans.factory.config.Scope 接口的类

Spring 参考中有一个完整的章节介绍了自定义范围的实现:Spring Reference Chapter 4.5.5 Custom scopes

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 2011-12-30
    • 1970-01-01
    • 2014-01-19
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    相关资源
    最近更新 更多