如何从值堆栈中删除操作? [英] How to remove actions from the value stack?

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

问题描述

我正在尝试使我的动作类单身.关键是要使动作类在MVC模式中成为 real 控制器.特别是在实现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.

Struts2也有一个默认范围,它也是单例.我想将动作类放入此范围,并将其从值堆栈中删除.

Struts2 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.

如何修改Struts2框架以使自己的动作像Spring中的控制器一样?我知道我只能将动作类的管理委派给Spring,但是我不能使用默认范围,并且Struts2容器仍然保持运行状态.我无法将其从框架中删除,因为它不可插入.

How could I modify Struts2 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 Struts2 container is still keep running. I can't remove it from the framework, because it's not pluggable.

因此,piggy带在Spring和Struts2容器周围,我无法使我的动作类成为单例,因为Struts2实例化了它们并将其放入值堆栈.这是我的问题:如果我在Struts和Spring之间选择容器以将动作类置于默认范围内,我怎么能告诉Struts2框架不要将它们放入值堆栈中?

So, piggybacking around Spring and Struts2 container I can't make my action classes singletons because Struts2 instantiate them and put to the value stack. That is my question: if I choose the container between Struts and Spring to put my action classes to default scope, how could I tell Struts2 framework not to put them to the value stack?

推荐答案

假设您使用的是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.)

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

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