You can't create beans that implement java.lang.String, it's immutable and doesn't follow the bean spec. (*Chris*)
On Sun, May 8, 2011 at 2:11 PM, Marcus Bond <mar...@marcusbond.co.uk> wrote: > Hi, > > 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: > > http://localhost:8080/MyApp/simple#this%20is%20a%20java.lang.String%20bean%20in%20my%20spring%20context > > 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: > http://localhost:8080/MyApp/simple > > 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="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:aop="http://www.springframework.org/schema/aop" > xmlns:tx="http://www.springframework.org/schema/tx" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.5.xsd > http://www.springframework.org/schema/tx > http://www.springframework.org/schema/tx/spring-tx-2.5.xsd > http://www.springframework.org/schema/aop > http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> > > <!-- 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" /> > </bean> > > <!-- action beans --> > <bean name ="simpleAction" class="uk.co.marcusbond.action.SimpleAction" > scope="prototype" /> > </beans> > > *Struts file:* > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE struts PUBLIC > "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" > "http://struts.apache.org/dtds/struts-2.0.dtd"> > <struts> > <package name="simple" extends="struts-default"> > <!-- returns success and shows index.html --> > <action name="simple" > class="simpleAction"> > <result>index.html</result> > </action> > > <!-- redirects through the 'simple' action --> > <action name="simpleRedirect"> > <result name="success" type="redirect">simple</result> > </action> > </package> > </struts> > > *Java class uk.co.marcusbond.action.SimpleAction* > package uk.co.marcusbond.action; > > public class SimpleAction { > > public String execute() { > return "success"; > } > } > > >