如何从 ValueStack 中删除操作? [英] How to remove actions from the ValueStack?

查看:39
本文介绍了如何从 ValueStack 中删除操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的动作类成为单例.重点是使动作类真正 MVC 模式中的控制器.特别是在实现 REST 控制器时,控制器的范围可以扩展到应用程序的生命周期.就像在 Spring 框架中一样,控制器默认被置于默认范围内,Spring 中的默认范围是单例.

I'm trying to make my action classes singletons. The point is to make action classes real controllers in MVC pattern. Especially when implementing REST controllers the scope of the controller could be extended to the life of the application. Like in Spring framework the controller is put to the default scope by default, the default scope in Spring is singleton.

Struts 2 也有一个默认的作用域,它也是单例的.我想将我的操作类放到这个范围内,并将它们从值堆栈中删除.

Struts 2 has also a default scope, and it's also singleton. I want to put my action classes to this scope and remove them from the value stack.

我如何修改 Struts 2 框架以使我的操作类似于 Spring 中的控制器?我知道我可以将操作类的管理委托给 Spring,但我不能使用默认范围,并且 Struts 2 容器仍在运行.我无法从框架中删除它,因为它不可插入.

How could I modify Struts 2 framework to make my actions like a controller in Spring? I know that I could just delegate management of action classes to Spring, but I can't use a default scope, and Struts 2 container is still keep running. I can't remove it from the framework, because it's not pluggable.

因此,在 Spring 和 Struts2 容器中走动时,我无法使我的操作类成为单例,因为 Struts 2 实例化并将它们放入 ValueStack.

So, walking around Spring and Struts2 container I can't make my action classes singletons because Struts 2 instantiate and put them to the ValueStack.

这是我的问题:

如果我选择 Struts 2 和 Spring 之间的容器来将我的操作类放入默认范围,我怎么能告诉 Struts 2 框架不要将它们放入 ValueStack?

If I choose the container between Struts 2 and Spring to put my action classes to default scope, how could I tell Struts 2 framework not to put them to the ValueStack?

推荐答案

假设您正在使用 XWork 的 DefaultActionInvocation 实现,它在那里通过 init 方法完成.拉出来有点麻烦,因为它位于 XWork 和 S2 中的动作代理和动作代理工厂之下.

Assuming you're using XWork's DefaultActionInvocation implementation, it's done there, by the init method. Pulling that out is a bit of a pain because it's layered underneath action proxies and action proxy factories in both XWork and S2.

也就是说,我会非常犹豫是否做出这样的改变;它具有系统范围的影响,并且本质上与关于 XW/WW/S2 的一切背道而驰.

That said, I'd be very hesitant at making a change like this; it has system-wide implications and is counter to essentially everything about XW/WW/S2.

(不相关,但单例性质并不是定义控制器的,而是定义组件是什么的职责.)

(Unrelated, but singleton nature isn't what defines a controller, it's the responsibilities that define what a component is.)

这篇关于如何从 ValueStack 中删除操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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