Announcement Announcement Module
Collapse
No announcement yet.
@Scope request and prototype in 3.1.2 with struts2 controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Scope request and prototype in 3.1.2 with struts2 controllers

    I am trying to upgrade from 3.0.3 to 3.1.2. It is a struts2 app, with a controller/action marked as @Scope("request"). A new action object is created on each request. The action bean has a SearchCriteria object injected into it. The SearchCriteria class is marked with @Scope("prototype"). So I'd expect a new one to get created on every request, which is how it worked with spring 3.0.3. But now first time it sees it as a prototype and creates a new one, but from then on it uses a cached version. I've tried to debug it, but am getting no where fast.

    Maybe there is a new configuration setting I'm not aware of? Or any other ideas would be appreciated.

    Thanks,
    Steve

  • #2
    The fastest and straight forward resolution to this would be to give the scope REQUEST to the SearchCriteria bean as well. Thus every request would be provided with a new instance of SearchCriteria every time. I could have suggested using <aop:scoped-proxy> on the action if your action is getting injected in your SearchCriteria but you can't do this as your SearchCriteria is prototype scope and AOP Scoped proxies doesn't work on singleton or prototype scoped beans and would throw BeanCreationEXception. You may read here

    Comment


    • #3
      I did try setting both to scope of request, without success.

      Comment


      • #4
        Trust me on this. Your DEV environment might be doing this crazy behavior. Did you restart your Eclipse/STS and/or application server? If on windows, I may also recommend to restart Windows. Did you confirm that your changes are present in deployment directory of application server after you set the scope of both to REQUEST? There's no reason for it not to work. One more thing to make sure is that both the beans should be declared inside a WebApplicationContext and not the FileSystemApplicationContext or ClasspathApplicationContext? Can you paste the spring configuration as seen by your dispatcher-servlet? That would help in analyzing the issue. Actually request scope is only available inside a WebApplicationContext.

        Comment

        Working...
        X