com.opensymphony.xwork2.spring.SpringObjectFactory does'nt create bean when
alwaysRespectAutowireStrategy=false
---------------------------------------------------------------------------------------------------------------
Key: WW-3147
URL: https://issues.apache.org/struts/browse/WW-3147
Project: Struts 2
Issue Type: Bug
Components: Plugin - Spring
Affects Versions: 2.1.6
Environment: Struts-2.1.6
TC 6.0.14
J2SDK 6.0.14
Reporter: Martin Gainty
//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;
try {
//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) {
autoWiringFactory.autowireBeanProperties(bean,
autowireStrategy, false);
}
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}
*/
public Object buildBean(Class clazz, Map extraContext) throws Exception {
return clazz.newInstance();
}
private void injectApplicationContext(Object bean) {
if (bean instanceof ApplicationContextAware) {
((ApplicationContextAware) bean).setApplicationContext(appContext);
}
}
/*** @param obj */
protected Object injectInternalBeans(Object obj) {
if (obj != null && container != null) {
container.inject(obj);
}
return obj;
}
//a very good likelihood that the returned bean will be null in the else
condition as it is never created
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.