views:

54

answers:

2

Is there any reason why a request scoped Spring object would be cached between requests, by a injected @SpringBean field?

+1  A: 

The Spring bean shouldn't be, no, but Wicket doesn't inject the Spring bean directly into the wicket component, it generates a serializable proxy for the target spring bean definition, and injects that into your component. That proxy may be cached, dependening on your wicket component, but the target spring bean is still managed by Spring itself, and request scoped beans should remain so.

Without any more information as to why you're asking the question, I can't be much more help than that, other than to suggest you turn on DEBUG-level logging for Spring, and watch the request-scoped bean being created.

skaffman
Thanks, skaffman. That's exactly the behavior I expected when suggesting it. A team I'm working on has experience the expected behavior of request scoped beans when obtaining the reference by asking the spring context for it. However, if we inject the bean via @SpringBean we fail to see subsequent bean instances being created for each request.We have a work around. But I'll be sure to turn on Spring debug logging and see if that might lead to some conclusion.
Matt
A: 

I believe you need to use the targetClass scoped-proxy type for it to work, and don't forget the:

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
slckin