Why is Struts2 spring plugin wiring internal spring classes by type when autowire config value is "no"

38 Views Asked by At

Struts version: 2.5.30

Struts Spring Configuration:

    <constant name="struts.objectFactory" value="spring" />
    <!-- spring injection wont auto happen.  Need to annotate with @autowired -->
    <constant name="struts.objectFactory.spring.autoWire" value="no" />

Action Mapping:

        <action name="loginAuthentication" class="com.webexchange.actions.security.Login" method="executeNoSecurity">
            <interceptor-ref name="token" />
            <interceptor-ref name="stackWithSecurity" />

            <result name="success" type="redirectAction">
                <param name="actionName">${forwardUrl}</param>
                <param name="namespace">${forwardNamespace}</param>
                <param name="struts.token.name">token</param>
                <param name="token">${token}</param>
            </result>
            <result name="input">/Login.jsp</result>
            <result name="invalid.token">/WEB-INF/jsp/centers/common/SystemActionErrors.jsp</result>
        </action>

String spring bean introduced which is causing this behavior to occur

    @Bean("passwordRuleString")
    public String passwordRuleString(@Autowired @Qualifier("passwordRuleList") List<String> passwordRuleList) {

       StringBuilder sb = new StringBuilder();

        sb.append("Password must be ");

        boolean comma = false;

        for (String s : passwordRuleList){
            if(comma) {
                sb.append(", ");
            }
            sb.append(s);
            comma = true;
        }

        return sb.toString();
    }
}

Based on the result type, struts runs the following constructor org.apache.struts2.result.ServletActionRedirectResult#ServletActionRedirectResult(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

Intellij ServletActionRedirectResult debug

All the the parameter strings have been injected with the String spring bean instance. However, I do have the struts.objectFactory.spring.autoWire setting set to "no". This is defined as "Turn off externally defined autowiring. Annotation-driven injection and injection based on Springs *Aware-interfaces still applies" in the documentation. https://struts.apache.org/plugins/spring/

Most of these get overwritten after the constructor is called, however, the methodName value remains and causes the redirect to append it to my url

/myNamespace/myAction.action!Password must be Min length of 5, Contain at least 1 Number, Contain at least 1 Letter

instead of the expected

/myNamespace/myAction.action

The issue ends up creating a 404 result in my application.

Is there a configuration setting to stop Struts from internally autowiring by type, is this a bug, or do I need to only create spring beans with my own classes when using with Struts?

0

There are 0 best solutions below