Running Struts 1 actions from Spring

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:

  1. Use the Spring ContextLoaderPlugin in the struts-config file.
  2. Override the Struts request processor with Spring’s delegating request processor.
  3. 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:

  1. If you are using Tiles as well as Struts, you need to use Spring’s DelegatingTilesRequestProcessor rather than just the DelegatingRequestProcessor.
  2. 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.
  3. 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.

This entry was posted in Groovy, Spring and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags are not allowed.

517,762 Spambots Blocked by Simple Comments