From d788700009a09a2ae9ca7107008cbe773dc2b3f5 Mon Sep 17 00:00:00 2001 From: Johannes Geppert Date: Sun, 7 Jun 2015 11:35:46 +0200 Subject: [PATCH] WW-4510 Upgrade spring plugin dependencies to spring version 4.x --- plugins/spring/pom.xml | 8 +++++ .../spring/StrutsSpringObjectFactory.java | 18 ++++------- .../spring/StrutsSpringObjectFactoryTest.java | 8 ++--- pom.xml | 2 +- .../xwork2/spring/SpringObjectFactory.java | 28 +++++------------ .../spring/SpringProxyableObjectFactory.java | 31 ++++++------------- 6 files changed, 36 insertions(+), 59 deletions(-) diff --git a/plugins/spring/pom.xml b/plugins/spring/pom.xml index 0b06dbdee..4e509f1e7 100644 --- a/plugins/spring/pom.xml +++ b/plugins/spring/pom.xml @@ -77,6 +77,14 @@ test + + + javax.servlet + javax.servlet-api + 3.1.0 + test + diff --git a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java index c34a6e4a3..f4a6f31dd 100644 --- a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java +++ b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java @@ -24,10 +24,10 @@ package org.apache.struts2.spring; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.spring.SpringObjectFactory; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.apache.struts2.StrutsConstants; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.StrutsConstants; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.web.context.WebApplicationContext; @@ -74,9 +74,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory { super(); boolean useClassCache = "true".equals(useClassCacheStr); - if (LOG.isInfoEnabled()) { - LOG.info("Initializing Struts-Spring integration..."); - } + LOG.info("Initializing Struts-Spring integration..."); Object rootWebApplicationContext = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); @@ -112,9 +110,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory { ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext) appContext; reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext, "true".equals(reloadConfig)); - if (LOG.isInfoEnabled()) { - LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!", watchList); - } + LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!\n{}", watchList); setClassLoader(reloadingContext.getReloadingClassLoader()); @@ -144,8 +140,6 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory { this.setEnableAopSupport(enableAopSupport); - if (LOG.isInfoEnabled()) { - LOG.info("... initialized Struts-Spring integration successfully"); - } + LOG.info("... initialized Struts-Spring integration successfully"); } } diff --git a/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java b/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java index 92ce5a4ee..9141b02d6 100644 --- a/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java +++ b/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java @@ -21,10 +21,8 @@ package org.apache.struts2.spring; -import javax.servlet.ServletContext; - +import com.opensymphony.xwork2.inject.Container; import junit.framework.TestCase; -import org.apache.struts2.StrutsConstants; import org.easymock.EasyMock; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.mock.web.MockServletContext; @@ -32,7 +30,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext; -import com.opensymphony.xwork2.inject.Container; +import javax.servlet.ServletContext; /** * Unit test for {@link StrutsSpringObjectFactory}. @@ -55,7 +53,7 @@ public class StrutsSpringObjectFactoryTest extends TestCase { EasyMock.replay(container); ConfigurableWebApplicationContext ac = new XmlWebApplicationContext(); - ServletContext msc = (ServletContext) new MockServletContext(); + ServletContext msc = new MockServletContext(); msc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac); ac.setServletContext(msc); ac.setConfigLocations(new String[] {"org/apache/struts2/spring/StrutsSpringObjectFactoryTest-applicationContext.xml"}); diff --git a/pom.xml b/pom.xml index 9fdec9d45..bf48092a5 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ ${project.version} - 3.0.5.RELEASE + 4.1.6.RELEASE 3.0.6 3.3 5.0.2 diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java index 2cfb09190..718480f33 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java @@ -17,8 +17,8 @@ package com.opensymphony.xwork2.spring; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.inject.Inject; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.BeansException; import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -70,8 +70,7 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon * * @param appContext The Spring ApplicationContext that should be used to look beans up with. */ - public void setApplicationContext(ApplicationContext appContext) - throws BeansException { + public void setApplicationContext(ApplicationContext appContext) throws BeansException { this.appContext = appContext; autoWiringFactory = findAutoWiringBeanFactory(this.appContext); } @@ -84,33 +83,23 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon public void setAutowireStrategy(int autowireStrategy) { switch (autowireStrategy) { case AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT: - if (LOG.isInfoEnabled()) { - LOG.info("Setting autowire strategy to autodetect"); - } + LOG.info("Setting autowire strategy to autodetect"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_BY_NAME: - if (LOG.isInfoEnabled()) { - LOG.info("Setting autowire strategy to name"); - } + LOG.info("Setting autowire strategy to name"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE: - if (LOG.isInfoEnabled()) { - LOG.info("Setting autowire strategy to type"); - } + LOG.info("Setting autowire strategy to type"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR: - if (LOG.isInfoEnabled()) { - LOG.info("Setting autowire strategy to constructor"); - } + LOG.info("Setting autowire strategy to constructor"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_NO: - if (LOG.isInfoEnabled()) { - LOG.info("Setting autowire strategy to none"); - } + LOG.info("Setting autowire strategy to none"); this.autowireStrategy = autowireStrategy; break; default: @@ -198,8 +187,7 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon return autoWireBean(bean, autoWiringFactory); } } catch (UnsatisfiedDependencyException e) { - if (LOG.isErrorEnabled()) - LOG.error("Error building bean", e); + LOG.error("Error building bean", e); // Fall back return autoWireBean(super.buildBean(clazz, extraContext), autoWiringFactory); } diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java index 616ac0f9d..3f701a1cb 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java @@ -15,9 +15,10 @@ */ package com.opensymphony.xwork2.spring; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationContext; @@ -39,36 +40,26 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory { @Override public Object buildBean(String beanName, Map extraContext) throws Exception { - if (LOG.isDebugEnabled()) { - LOG.debug("Building bean for name " + beanName); - } + LOG.debug("Building bean for name {}", beanName); if (!skipBeanNames.contains(beanName)) { ApplicationContext anAppContext = getApplicationContext(extraContext); try { - if (LOG.isDebugEnabled()) { - LOG.debug("Trying the application context... appContext = " + anAppContext + ",\n bean name = " + beanName); - } + LOG.debug("Trying the application context... appContext = {},\n bean name = {}", anAppContext, beanName); return anAppContext.getBean(beanName); } catch (NoSuchBeanDefinitionException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Did not find bean definition for bean named " + beanName + ", creating a new one..."); - } + LOG.debug("Did not find bean definition for bean named {}, creating a new one...", beanName); if (autoWiringFactory instanceof BeanDefinitionRegistry) { try { Class clazz = Class.forName(beanName); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) autoWiringFactory; - RootBeanDefinition def = new RootBeanDefinition(clazz, autowireStrategy); - def.setSingleton(false); - if (LOG.isDebugEnabled()) { - LOG.debug("Registering a new bean definition for class " + beanName); - } + RootBeanDefinition def = new RootBeanDefinition(clazz, autowireStrategy, true); + def.setScope(BeanDefinition.SCOPE_SINGLETON); + LOG.debug("Registering a new bean definition for class {}", beanName); registry.registerBeanDefinition(beanName,def); try { return anAppContext.getBean(beanName); } catch (NoSuchBeanDefinitionException e2) { - if (LOG.isWarnEnabled()) { - LOG.warn("Could not register new bean definition for bean " + beanName); - } + LOG.warn("Could not register new bean definition for bean {}", beanName); skipBeanNames.add(beanName); } } catch (ClassNotFoundException e1) { @@ -77,9 +68,7 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory { } } } - if (LOG.isDebugEnabled()) { - LOG.debug("Returning autowired instance created by default ObjectFactory"); - } + LOG.debug("Returning autowired instance created by default ObjectFactory"); return autoWireBean(super.buildBean(beanName, extraContext), autoWiringFactory); }