Spring请求Scoped Bean存在于后续请求中

时间:2013-12-30 13:03:30

标签: java spring spring-mvc spring-security

我有一个控制器(Scoped:session),一个自动服务(Scoped:session)和一个服务使用的组件(“A”)(Scoped:request)。

每个请求的流程预计如下:

1) Request Arrives at Controller
2) Controller has an injected service whose method is called
3) Service has an injected component A, and the method of that is called has 
   a custom PreAuthorize expression evaluating a boolean returned by the 
   method of the injected component A.
4) In successful PreAuthorize (doesn't throw access denied and it goes ahead) 
   I populate a member variable of bean A.
5) The service method is executed which uses bean A's set member variables' 
   value.

每次发出请求时,我都会得到成员变量的值相同。基本上,它是第一次请求时的值。我在每个PreAuthorize上更改它...如果我调试并看到发生了什么,它确实会被更改,但是当我在组件自动装配的服务上访问bean时,我得到旧值。

所以我在服务中为bean A(请求作用域)打印了object.toString。我应该在每个新请求上得到不同的值。但我一直都有同样的价值。

我做错了什么?对于请求作用域的组件,这是标准/正确的行为吗?

以下方案完美无缺,因为我得到了更改的值,因为我在同一个会话作用域的对象中得到了更新的值:

Controller(Scoped:session),Service(Scoped:session),Component(Scoped:session)..

修改 同样,如果所有3都是作用域请求,我会得到不同的bean的toString值。

编辑2 稍微考虑一下,是否返回相同的Component bean,因为它是Session作用域服务/控制器的成员?我尝试了Controller(会话),服务(请求)和组件(请求),并在会话中获得了与自动装配组件相同的object.toString。 PreAuthorize访问正确的bean,因为它没有访问自动连接到服务的实例。

那么,当我说时,我是正确的,将请求范围的bean自动连接到会话作用域控制器(“较大”范围内的“较小”范围)是不正确的吗?

0 个答案:

没有答案
相关问题