diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java index 69d812da37..b7dbb399b6 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java @@ -470,7 +470,6 @@ public class ContextLoader { protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { List>> initializerClasses = determineContextInitializerClasses(servletContext); - if (initializerClasses.size() == 0) { // no ApplicationContextInitializers have been declared -> nothing to do return; @@ -483,11 +482,13 @@ public class ContextLoader { for (Class> initializerClass : initializerClasses) { Class initializerContextClass = GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class); - Assert.isAssignable(initializerContextClass, contextClass, String.format( - "Could not add context initializer [%s] as its generic parameter [%s] " + - "is not assignable from the type of application context used by this " + - "context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(), - contextClass.getName())); + if (initializerContextClass != null) { + Assert.isAssignable(initializerContextClass, contextClass, String.format( + "Could not add context initializer [%s] as its generic parameter [%s] " + + "is not assignable from the type of application context used by this " + + "context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(), + contextClass.getName())); + } initializerInstances.add(BeanUtils.instantiateClass(initializerClass)); }