Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.1.1
-
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):
- InstantiationAwareBeanPostProcessor.applyBeanPostProcessorsBeforeInstantiation
- InstantiationAwareBeanPostProcessor.applyBeanPostProcessorsAfterInitialization
- doCreateBean
- createBeanInstance
- populateBean
- InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation
- autowire, for example AUTOWIRE_BY_NAME,AUTOWIRE_BY_TYPE
- InstantiationAwareBeanPostProcessor.postProcessPropertyValues
- applyPropertyValues
- initializeBean
- invokeAwareMethods
- BeanPostProcessor.postProcessBeforeInitialization
- invokeInitMethods
- BeanPostProcessor.postProcessAfterInitialization
- 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