diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java index ea73248eb77..a594683c5e6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import javax.servlet.ServletContext; +import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanFactory; @@ -42,20 +43,22 @@ import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.ServletContextResourcePatternResolver; /** - * A mock WebApplicationContext that accepts registrations of object instances. + * A stub WebApplicationContext that accepts registrations of object instances. * - *
As registered object instances are instantiated and initialized - * externally, there is no wiring, bean initialization, lifecycle events, as - * well as no pre-processing and post-processing hooks typically associated with - * beans managed by an {@link ApplicationContext}. Just a simple lookup into a + *
As registered object instances are instantiated and initialized externally,
+ * there is no wiring, bean initialization, lifecycle events, as well as no
+ * pre-processing and post-processing hooks typically associated with beans
+ * managed by an {@link ApplicationContext}. Just a simple lookup into a
* {@link StaticListableBeanFactory}.
*
* @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 3.2
*/
class StubWebApplicationContext implements WebApplicationContext {
@@ -77,14 +80,12 @@ class StubWebApplicationContext implements WebApplicationContext {
private final ResourcePatternResolver resourcePatternResolver;
- /**
- * Class constructor.
- */
public StubWebApplicationContext(ServletContext servletContext) {
this.servletContext = servletContext;
this.resourcePatternResolver = new ServletContextResourcePatternResolver(servletContext);
}
+
/**
* Returns an instance that can initialize {@link ApplicationContextAware} beans.
*/
@@ -98,6 +99,7 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.servletContext;
}
+
//---------------------------------------------------------------------
// Implementation of ApplicationContext interface
//---------------------------------------------------------------------
@@ -137,12 +139,16 @@ class StubWebApplicationContext implements WebApplicationContext {
}
public void addBeans(List> beans) {
+ if (beans == null) {
+ return;
+ }
for (Object bean : beans) {
String name = bean.getClass().getName() + "#" + ObjectUtils.getIdentityHexString(bean);
this.beanFactory.addBean(name, bean);
}
}
+
//---------------------------------------------------------------------
// Implementation of BeanFactory interface
//---------------------------------------------------------------------
@@ -202,6 +208,7 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.beanFactory.getAliases(name);
}
+
//---------------------------------------------------------------------
// Implementation of ListableBeanFactory interface
//---------------------------------------------------------------------
@@ -262,6 +269,7 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.beanFactory.findAnnotationOnBean(beanName, annotationType);
}
+
//---------------------------------------------------------------------
// Implementation of HierarchicalBeanFactory interface
//---------------------------------------------------------------------
@@ -276,6 +284,7 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.beanFactory.containsBean(name);
}
+
//---------------------------------------------------------------------
// Implementation of MessageSource interface
//---------------------------------------------------------------------
@@ -295,13 +304,14 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.messageSource.getMessage(resolvable, locale);
}
+
//---------------------------------------------------------------------
// Implementation of ResourceLoader interface
//---------------------------------------------------------------------
@Override
public ClassLoader getClassLoader() {
- return null;
+ return ClassUtils.getDefaultClassLoader();
}
@Override
@@ -309,6 +319,7 @@ class StubWebApplicationContext implements WebApplicationContext {
return this.resourcePatternResolver.getResource(location);
}
+
//---------------------------------------------------------------------
// Other
//---------------------------------------------------------------------
@@ -340,65 +351,61 @@ class StubWebApplicationContext implements WebApplicationContext {
@Override
public