struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcus Bond <>
Subject Strange behaviour with Spring
Date Sun, 08 May 2011 21:11:23 GMT

I'm using Struts 2.2.3 and have observed some bizarre behavior when 
using Spring to provide my actions.. In order to simplify this and prove 
the problem I have created a project with a single static html file, and 
a single action in struts.xml which references a bean in my spring 
context file.

What basically happens is that if I declare a bean in my spring context 
(bean unrelated toany struts action) that is of class java.lang.String 
(as I do for a log4j filepath) then when I perform a redirect in an 
action mapping this gets appended to the end of the url as the anchor.

If I navigate to http://localhost:8080/My App/simpleRedirect
the result is a reirect to the 'simple' action but note the url struts 
has redirected to:

For some reason the org.apache.struts2.dispatcher.ServletRedirectResult 
class is being instantiated by with the anchor and location constructor 
args set to the value of my spring bean by the StrutsSpringObjectFactory

If I remove the String bean from the spring contect then the url behaves 
as normal, redirecting to:

Have been scratching my head trying to find where this behaviour is 
happening but have run out of time.. is this a known issue?

Files content:
*Spring context file:*

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

     <!-- Expose String as a bean (usually for a file path)-->
     <!-- Picked up by Struts and set as location and anchor on a redirect and presented
in url
         If commented out this does not happen -->
     <bean id="someFileName" class="java.lang.String">
         <constructor-arg value="this is a java.lang.String bean in my spring context"

     <!--  action beans -->
     <bean name ="simpleAction" class="" scope="prototype"

*Struts file:*
<?xml version="1.0" encoding="UTF-8"?>
     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     <package name="simple" extends="struts-default">
         <!-- returns success and shows index.html -->
         <action name="simple"

         <!-- redirects through the 'simple' action -->
         <action name="simpleRedirect">
                 <result name="success" type="redirect">simple</result>

*Java class*

public class SimpleAction  {

     public String execute() {
	return "success";

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message