You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "JB (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2011/11/26 05:10:40 UTC

[jira] [Issue Comment Edited] (WW-3647) Adding a jndi-lookup Spring bean breaks ServletActionRedirectResult

    [ https://issues.apache.org/jira/browse/WW-3647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13157363#comment-13157363 ] 

JB edited comment on WW-3647 at 11/26/11 4:10 AM:
--------------------------------------------------

I don't have a patch ready (yet); however a temporary work-around is to configure the following setting in either your struts.xml or struts.properties file:

*struts.xml*
{code:xml}
<struts>

<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />

</struts>
{code}

*struts.properties*
{code}
struts.objectFactory.spring.autoWire.alwaysRespect = true
{code}

In the *buildBean* method of *SpringObjectFactory* class, if the *alwaysRespectAutowireStrategy* variable has a "true" value the error is not produced.  Based on the code's comments the mixed injection strategy appears to be the root of the problem.  if Spring is utilized for bean creation -- exclusively -- the error does not arise.

*com.opensymphony.xwork2.spring.SpringObjectFactory*

{code}

public class SpringObjectFactory extends ObjectFactory implements ApplicationContextAware {

[...]

public Object buildBean(Class clazz, Map<String, Object> extraContext)

[...]

    // Decide to follow autowire strategy or use the legacy approach which mixes injection strategies
    if (alwaysRespectAutowireStrategy) {
        // Leave the creation up to Spring
        bean = autoWiringFactory.createBean(clazz, autowireStrategy, false);
        injectApplicationContext(bean);
        return injectInternalBeans(bean);
    } else {
        bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
        bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean,     bean.getClass().getName());

[...]

}
{code}

           
                
      was (Author: jeffblack360):
    I don't have a patch ready (yet); however a temporary work-around is to configure the following setting in either your struts.xml or struts.properties file:

*struts.xml*
{code:xml}
<struts>

<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />

</struts>
{code}

*struts.properties*
{code}
struts.objectFactory.spring.autoWire.alwaysRespect = true
{code}

In the *buildBean* method of *SpringObjectFactory* class, if the *alwaysRespectAutowireStrategy* variable has a "true" value the error is not produced.  Based on the code's comments the mixed injection strategy appears to be the root of the problem.  if Spring is utilized for bean creation the error does not arise.

*com.opensymphony.xwork2.spring.SpringObjectFactory*

{code}

public class SpringObjectFactory extends ObjectFactory implements ApplicationContextAware {

[...]

public Object buildBean(Class clazz, Map<String, Object> extraContext)

[...]

    // Decide to follow autowire strategy or use the legacy approach which mixes injection strategies
    if (alwaysRespectAutowireStrategy) {
        // Leave the creation up to Spring
        bean = autoWiringFactory.createBean(clazz, autowireStrategy, false);
        injectApplicationContext(bean);
        return injectInternalBeans(bean);
    } else {
        bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
        bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean,     bean.getClass().getName());

[...]

}
{code}

           
                  
> Adding a jndi-lookup Spring bean breaks ServletActionRedirectResult
> -------------------------------------------------------------------
>
>                 Key: WW-3647
>                 URL: https://issues.apache.org/jira/browse/WW-3647
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter, Plugin - Spring
>    Affects Versions: 2.2.3
>            Reporter: Miguel Almeida
>            Assignee: Lukasz Lenart
>              Labels: injection, redirectAction, spring, struts2
>         Attachments: redirectActionErrorTest.zip, redirectActionErrorWithJunitTest.zip
>
>
> When you add the following bean to a Spring-Struts application:
> <jee:jndi-lookup jndi-name="someName" id="currentEnvironment" default-value="XXXX"  />
> Whenever you have an action with a redirectAction type, Struts will try to redirect you to:
> http://localhost:8080/XXXX/index!XXXX.action#XXXX
> This happens because the 3 String argument constructor for ServletActionRedirectResult will set action, method and namespace to whatever value is defined for that bean (XXXX in the example, if you don't have a someName JDNI property).
> This only happens when you let struts manage ServletActionRedirectResult. If you add the following Spring bean:
> 	<bean id="myRedirect" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"
> 		scope="prototype" autowire="byName">
> 	</bean>
> and add a 			<result-type name="myRedirect"	class="myRedirect" /> result type, the problem doesn't appear.
> I've added a testCase for you to confirm.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira