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 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.
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.
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
.
This is my question:
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
?
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.
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.)