WW-4110 Adds special flag to use different logic when creating AOP beans

This commit is contained in:
Lukasz Lenart
2014-08-06 20:21:25 +02:00
parent 52481bd56d
commit ae324c9811
5 changed files with 28 additions and 2 deletions
@@ -155,6 +155,9 @@ public final class StrutsConstants {
/** Whether Spring should use its class cache or not */
public static final String STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE = "struts.objectFactory.spring.useClassCache";
/** Uses different logic to construct beans, see https://issues.apache.org/jira/browse/WW-4110 */
public static final String STRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT = "struts.objectFactory.spring.enableAopSupport";
/** Whether or not XSLT templates should not be cached */
public static final String STRUTS_XSLT_NOCACHE = "struts.xslt.nocache";
@@ -47,6 +47,11 @@ struts.objectFactory.spring.useClassCache = true
### valid values are: true, false (false is the default)
struts.objectFactory.spring.autoWire.alwaysRespect = false
### By default SpringObjectFactory doesn't support AOP
### This flag was added just temporally to check if nothing is broken
### See https://issues.apache.org/jira/browse/WW-4110
struts.objectFactory.spring.enableAopSupport = false
### if specified, the default object type determiner can be overridden here
### Note: short-hand notation is supported in some cases, such as "tiger" or "notiger"
### Alternatively, you can provide a com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation name here
@@ -67,6 +67,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE,required=false) String autoWire,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT,required=false) String alwaysAutoWire,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE,required=false) String useClassCacheStr,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT,required=false) String enableAopSupport,
@Inject ServletContext servletContext,
@Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
@Inject Container container) {
@@ -141,6 +142,8 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
this.setAlwaysRespectAutowireStrategy("true".equalsIgnoreCase(alwaysAutoWire));
this.setEnableAopSupport(enableAopSupport);
if (LOG.isInfoEnabled()) {
LOG.info("... initialized Struts-Spring integration successfully");
}
@@ -45,7 +45,7 @@ public class StrutsSpringObjectFactoryTest extends TestCase {
Container container = EasyMock.createNiceMock(Container.class);
EasyMock.replay(container);
StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory(null, null, null, new MockServletContext(), null, container);
StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory(null, null, null, null, new MockServletContext(), null, container);
assertEquals(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, fac.getAutowireStrategy());
}
@@ -60,7 +60,7 @@ public class StrutsSpringObjectFactoryTest extends TestCase {
ac.setServletContext(msc);
ac.setConfigLocations(new String[] {"org/apache/struts2/spring/StrutsSpringObjectFactoryTest-applicationContext.xml"});
ac.refresh();
StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null, null, msc, null, container);
StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null, null, null, msc, null, container);
assertEquals(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, fac.getAutowireStrategy());
}
@@ -47,6 +47,11 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
private final Map<String, Object> classes = new HashMap<String, Object>();
private boolean useClassCache = true;
private boolean alwaysRespectAutowireStrategy = false;
/**
* This is temporary solution, after validating can be removed
* @since 2.3.18
*/
private boolean enableAopSupport = false;
@Inject(value="applicationContextPath",required=false)
public void setApplicationContextPath(String ctx) {
@@ -55,6 +60,11 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
}
}
@Inject(value = "enableAopSupport", required = false)
public void setEnableAopSupport(String enableAopSupport) {
this.enableAopSupport = Boolean.parseBoolean(enableAopSupport);
}
/**
* Set the Spring ApplicationContext that should be used to look beans up with.
*
@@ -175,6 +185,11 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
bean = autoWiringFactory.createBean(clazz, autowireStrategy, false);
injectApplicationContext(bean);
return injectInternalBeans(bean);
} else if (enableAopSupport) {
bean = autoWiringFactory.createBean(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
bean = autoWireBean(bean, autoWiringFactory);
bean = autoWiringFactory.initializeBean(bean, bean.getClass().getName());
return bean;
} else {
bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName());