I've done some searching and followed examples and I am trying to inject into a struts action a simple string using spring DI and I am unsuccessful.
defined for all requests for the struts filter
defined as a listener in web.xml
my struts in action is
has field aString with setter,
it is defined is struts.xml on the classpath
and in applicationContext I have the bean wired up:
I would have thought the property name should have been 'aString' but the deployer complained
inside the execute method of the action, aString is null. Nothing was injected. No run time errors at the console. The setter is there. Do I need to access the applicationContext and do a get by id name? I thought the spring container using the context xml would set the string for me when it created the action. I also found something talking about a struts plug-in for configuring spring but I suspect that was for earlier versions of spring and struts and is now deprecated or do I still need that?
A) Overriding the Struts RequestProcessor with Spring’s DelegatingRequestProcessor.
B) Delegate Struts Action management to the Spring framework.
In the struts.xml file, I declare a plugin and provide as a parameter the location of applicationContext
for overriding the struts request processer add
or in the second way, I set the type in my struts action
which gives the spring container control over creating the object. The action will need to be declared in applicationContext.
Does this sound correct. I thought this would be easier than this. The examples of struts to spring I had seen previously did not include any of this.
Joined: Sep 24, 2008
I got around this. I did 2 things to fix this and I don't know which did what. I went and download a spring to struts integration plugin. Then I made sure to identify the class in struts.xml to what the id name for the bean was in applicationContext.
From my research, the ContextLoaderPlugin was for Struts 1 being that it worked with the ActionServlet.