mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-4510 Upgrade spring plugin dependencies to spring version 4.x
This commit is contained in:
@@ -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>
|
||||
|
||||
+6
-12
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -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"});
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+10
-21
@@ -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<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) {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user