I’ve now successfully updated our app so that the Struts 1 actions can be run from Spring. The method was pretty much as I originally described, but there are a few gotchas, so I’ll detail it:
- Use the Spring ContextLoaderPlugin in the struts-config file.
- Override the Struts request processor with Spring’s delegating request processor.
- Write an action-servlet.xml file to declare all of your Struts actions as Spring beans. The beans just need a name and class, as the other properties will still be read from your struts config file.
The gotchas I found are:
- If you are using Tiles as well as Struts, you need to use Spring’s DelegatingTilesRequestProcessor rather than just the DelegatingRequestProcessor.
- Struts permits two actions to be declared with the same URL path (I assume the second definition overrides the first one), but you can’t have two Spring beans with the same name so if you have duplicate entries in your struts config you need to exclude them from your Spring beans file.
- You need to exclude Struts definitions that just forward to other places rather than invoking actions as these obviously won’t require a Spring bean definition. e.g. ones that forward to tiles layouts
Next step: migrating from EJB2 to Spring beans.