【问题标题】:How does spring come to know about the new request or session?spring 如何知道新的请求或会话?
【发布时间】:2016-11-13 13:37:35
【问题描述】:

我知道在 web 应用程序中,对于它收到的每个请求,spring 都会在 ints 容器中创建一个新的 bean 实例。 我想知道 spring 如何区分请求并相应地创建新的 bean 实例?

【问题讨论】:

  • “对于它收到的每个请求,spring 都会创建一个新的 bean 实例”——谁告诉你的?
  • 第 11 分钟 link
  • 只要 bean 是请求范围内的

标签: java spring requestscope


【解决方案1】:

这项工作由Request context listener 完成,它根据传入的 http 请求决定实例化 bean,并在它们的生命周期结束后丢弃它们。 Session , Request 范围 bean 仅在应用程序上下文 web 感知时才相关,否则将抛出 IllegalStateException。

另外参考—— http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-other

【讨论】:

    猜你喜欢
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    相关资源
    最近更新 更多