diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index ed5f4c0b5b..f1a80bda42 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; +import org.springframework.beans.CachedIntrospectionResults; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -536,6 +537,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader // Propagate exception to caller. throw ex; } + + finally { + // Reset common introspection caches in Spring's core, since we + // might not ever need metadata for singleton beans anymore... + resetCommonCaches(); + } } } @@ -840,6 +847,18 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader this.active.set(false); } + /** + * Reset Spring's common core caches, in particular the {@link ResolvableType} + * and the {@link CachedIntrospectionResults} caches. + * @since 4.2 + * @see ResolvableType#clearCache() + * @see CachedIntrospectionResults#clearClassLoader(ClassLoader) + */ + protected void resetCommonCaches() { + ResolvableType.clearCache(); + CachedIntrospectionResults.clearClassLoader(getClassLoader()); + } + /** * Register a shutdown hook with the JVM runtime, closing this context diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 35b88c63ab..8432d75569 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1307,11 +1307,19 @@ public class ResolvableType implements Serializable { return resolvableType; } + /** + * Clear the internal {@code ResolvableType} cache. + * @since 4.2 + */ + public static void clearCache() { + cache.clear(); + } + /** * Strategy interface used to resolve {@link TypeVariable}s. */ - static interface VariableResolver extends Serializable { + interface VariableResolver extends Serializable { /** * Return the source of the resolver (used for hashCode and equals). @@ -1481,7 +1489,7 @@ public class ResolvableType implements Serializable { /** * The various kinds of bounds. */ - static enum Kind {UPPER, LOWER} + enum Kind {UPPER, LOWER} } }