Struts 2 将如何与 Spring 集成 [英] How Struts 2 will behave with Spring integration

查看:32
本文介绍了Struts 2 将如何与 Spring 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常 Struts 2 动作实例会根据请求创建.我的意思是每个请求都会创建新的操作实例.但是如果我与 Spring 集成,那么只会创建一个动作实例(如果我错了,我不确定是否纠正我).

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?

更多说明: 实例变量意味着,在 Struts 2 中,动作表单将不存在,因此您的动作本身作为获取请求参数的表单工作.第一个用户输入内容,第二个用户输入内容,并且都设置为一个实例操作.

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.

推荐答案

如果您的操作由 Struts 容器管理,那么 Struts 将在 default 范围内创建它们.

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

如果您的操作由 Spring 容器管理,那么您需要定义操作 bean 的作用域,因为 Spring 默认使用 singleton 作用域.

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.

如果您不想在用户请求之间共享您的操作 bean,您应该定义相应的范围.

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

您可以使用 prototype 作用域,这意味着每次构建 Struts 操作实例时,Spring 都会返回一个新实例.

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

这篇关于Struts 2 将如何与 Spring 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆