Skip to content

Commit

Permalink
WW-4510 Upgrade spring plugin dependencies to spring version 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jogep committed Jun 7, 2015
1 parent 72e6f70 commit d788700
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 58 deletions.
8 changes: 8 additions & 0 deletions plugins/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
<scope>test</scope>
</dependency>

<!-- The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher
So this is only necessary in tests-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
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.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
Expand Down Expand Up @@ -74,9 +74,7 @@ public StrutsSpringObjectFactory(

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);

Expand Down Expand Up @@ -112,9 +110,7 @@ public StrutsSpringObjectFactory(

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());

Expand Down Expand Up @@ -144,8 +140,6 @@ public StrutsSpringObjectFactory(

this.setEnableAopSupport(enableAopSupport);

if (LOG.isInfoEnabled()) {
LOG.info("... initialized Struts-Spring integration successfully");
}
LOG.info("... initialized Struts-Spring integration successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@

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;
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}.
Expand All @@ -55,7 +53,7 @@ public void testWithSpringContext() throws Exception {
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"});
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<properties>
<currentVersion>${project.version}</currentVersion>
<struts2.springPlatformVersion>3.0.5.RELEASE</struts2.springPlatformVersion>
<struts2.springPlatformVersion>4.1.6.RELEASE</struts2.springPlatformVersion>
<ognl.version>3.0.6</ognl.version>
<asm.version>3.3</asm.version>
<asm5.version>5.0.2</asm5.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

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;
Expand Down Expand Up @@ -70,8 +70,7 @@ public void setEnableAopSupport(String enableAopSupport) {
*
* @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);
}
Expand All @@ -84,33 +83,23 @@ public void setApplicationContext(ApplicationContext appContext)
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:
Expand Down Expand Up @@ -198,8 +187,7 @@ public Object buildBean(Class clazz, Map<String, Object> extraContext) throws Ex
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,36 +40,26 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory {

@Override
public Object buildBean(String beanName, Map<String, Object> 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) {
Expand All @@ -77,9 +68,7 @@ public Object buildBean(String beanName, Map<String, Object> extraContext) throw
}
}
}
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);
}

Expand Down

0 comments on commit d788700

Please sign in to comment.