How Struts 2 will behave with Spring integration

谁说我不能喝 提交于 2019-12-25 02:41:38

问题


Usually Struts 2 action instances will get create on the request. I mean per every request new action instance will get create. But if I integrate with Spring then there will be only one action instance will get create (I am not sure correct me if I am wrong).

So in this case what is if I have instance variables in the action class?

First user here will set that instance with some instance variables and second user may set there something. How it will behave at this time?

More clarification: Instance variable means, in Struts 2, action forms won't be there so, your action itself work as a form to get the request parameters. First user enters something and second user enters something and both are setting to one instance action.


回答1:


If your actions are managed by Struts container, then Struts is creating them in the default scope.

If your actions are managed by Spring container, then you need to define the scope of the action beans, because Spring by default uses singleton scope.

If you don't want to share your action beans between user's requests you should define the corresponding scope.

You can use prototype scope, which means a new instance is returned by the Spring each time Struts is being built an action instance.



来源:https://stackoverflow.com/questions/25464671/how-struts-2-will-behave-with-spring-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!