【问题标题】:Is it possible to obtain the Request Object in a request scoped bean?是否可以在请求范围的 bean 中获取请求对象?
【发布时间】:2010-06-25 15:24:43
【问题描述】:

我有一个声明为 scope="request" 的 bean。是否有机会获得在该范围内使用的请求?

<bean class="FooRequestAware" scope="request"/>

class FooRequestAware {
      private final Request req;
      public final bar() {}
}

【问题讨论】:

    标签: java spring request


    【解决方案1】:

    是的,只是自动接线

    public class FooRequestAware {
          private @Autowired HttpServletRequest req;
    
          public final bar() {}
    }
    

    【讨论】:

    猜你喜欢
    • 2011-04-19
    • 2013-01-21
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多