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

struts2+spring intergration,when user aop, maybe inject fail

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.1.1
    • 2.3.20
    • Plugin - Spring
    • None
    • Patch

    Description

      1.

          @Autowired
          private Resource resource; //no setter
      
      <action name="myAction" class="cn.javass.MyAction">
      

      2. use aop, for example

          <aop:config proxy-target-class="true">
              <aop:aspect ref="myAspect">
                  <aop:before method="before" pointcut="execution(* cn.javass.MyAction.*(..))"/>
              </aop:aspect>
          </aop:config>
      

      3. StrutsSpringObject

      bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
      bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName());
      // We don't need to call the init-method since one won't be registered.
      bean = autoWiringFactory.applyBeanPostProcessorsAfterInitialization(bean, bean.getClass().getName());  //generate proxy
      return autoWireBean(bean, autoWiringFactory); //inject error  because proxy
      

      spring`s processing flow :

      (org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory):

      1. InstantiationAwareBeanPostProcessor.applyBeanPostProcessorsBeforeInstantiation
      2. InstantiationAwareBeanPostProcessor.applyBeanPostProcessorsAfterInitialization
      3. doCreateBean
        1. createBeanInstance
        2. populateBean
          1. InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation
          2. autowire, for example AUTOWIRE_BY_NAME,AUTOWIRE_BY_TYPE
          3. InstantiationAwareBeanPostProcessor.postProcessPropertyValues
          4. applyPropertyValues
      4. initializeBean
        1. invokeAwareMethods
        2. BeanPostProcessor.postProcessBeforeInitialization
        3. invokeInitMethods
        4. BeanPostProcessor.postProcessAfterInitialization
      5. solution
        bean = autoWiringFactory.createBean(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
        bean = autoWireBean(bean, autoWiringFactory);
        bean = autoWiringFactory.initializeBean(bean, bean.getClass().getName());
        

      please delete src/main/java patch
      com.opensymphony.xwork2.spring.SpringObjectFactory
      test, will see resource is null;
      but use this patch will be not null

      Attachments

        1. test.rar
          30 kB
          zhangkaitao

        Activity

          People

            lukaszlenart Lukasz Lenart
            zhangkaitao zhangkaitao
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: