Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2479

SpringObjectFactory does not respect autowireStrategy

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.11
    • 2.1.3
    • Plugin - Spring
    • None

    Description

      SpringObjectFactory 's Object buildBean(Class clazz, Map extraContext) does not respect autowireStrategy as it first attempts to use AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR prior to using the default constructor. If the target bean has a candidate constructor, this leads to autowire="byType" semantics on the constructor values. This is highly undesireable in most circumstances, not to mention inconsistent with the semantics of "struts.objectFactory.spring.autoWire" in struts.properties

      I noticed this issue because I've been using the new @Autowired support in Spring 2.5. One of the difficulties with @Autowired is determining a way to use a PropertyPlaceholderConfigurer to configure simple configuration values on the target bean. One way to achieve this is to create a number of Integer / String beans configured by the PropertyPlaceholderConfigurer in the application context, and inject those beans into the target bean. However, creating a single String bean in one's application context will wreak havoc when AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR semantics are applied because of how common Strings are as constructor arguments. This seems to be the case with Framework classes created by SpringObjectFactory. For instance, ServletActionRedirectResult has the following constructor:

      ServletActionRedirectResult(String namespace, String actionName, String method)

      If there is a String bean in applicationContext.xml, this bean will be constructed not with it's actually supplied arguments from the framework, but with the value of the applicationContext.xml String bean! This is obviously not good.

      The same issue occurs with primative wrapper objects, and potentially any class.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mrdon Donald J. Brown
            btiernay Bob Tiernay
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment