Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
2.1.6
-
None
-
Struts-2.1.6
TC 6.0.14
J2SDK 6.0.14
-
Important
Description
//struts.objectFactory.spring.autoWire.alwaysRespect works fine when true
//Whether the autowire strategy should always be used, or the framework should try to guess the best strategy
//code works perfect as long as alwaysRepect=true
//analyzing alternative alwaysRepect=false nosedives into else guesswork code which may returns null
com.opensymphony.xwork2.spring.SpringObjectFactory
/*** @param clazz
- @param extraContext
- @throws Exception*/
@Override
public Object buildBean(Class clazz, Map<String, Object> extraContext) throws Exception {
Object bean;
tryUnknown macro: {//follow autowire strategy or use 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 { //wrong if you want type!="name" // autoWiringFactory = findAutoWiringBeanFactory(this.appContext); only in setContext bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName()); //only defined in org.springframework.beans.factory.config.AutowireCapableBeanFactory // Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) // We don't need to call the init-method since one won't be registered. bean = autoWiringFactory.applyBeanPostProcessorsAfterInitialization(bean, bean.getClass().getName()); //only defined in org.springframework.beans.factory.config.AutowireCapableBeanFactory // Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) return autoWireBean(bean, autoWiringFactory); //returns NULL } }catch (UnsatisfiedDependencyException e)
{ if (LOG.isErrorEnabled()) LOG.error("Error building bean", e); // Fall back return autoWireBean(super.buildBean(clazz, extraContext), autoWiringFactory); }}
public Object autoWireBean(Object bean, AutowireCapableBeanFactory autoWiringFactory) {
if (autoWiringFactory != null)
injectApplicationContext(bean);
injectInternalBeans(bean);
return bean;
}
com.opensymphony.xwork2.ObjectFactory
/*** Build a generic Java object of the given type.
- @param clazz the type of Object to build
- @param extraContext a Map of extra context which uses the same keys as the
{@link com.opensymphony.xwork2.ActionContext}
*/
{ return clazz.newInstance(); }
public Object buildBean(Class clazz, Map extraContext) throws Exception
private void injectApplicationContext(Object bean) {
if (bean instanceof ApplicationContextAware)
}
/*** @param obj */
protected Object injectInternalBeans(Object obj) {
if (obj != null && container != null)
return obj;
}
//a very good likelihood that the returned bean will be null in the else condition as it is never created