From fdc14a16eece63fd5af1d20980c8c9f21982cc12 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 9 Dec 2015 19:25:27 +0100 Subject: [PATCH] AbstractApplicationContext clears ReflectionUtils cache as well Issue: SPR-13783 --- .../context/support/AbstractApplicationContext.java | 7 +++++-- .../java/org/springframework/util/ReflectionUtils.java | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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 c8a597dc8d..a3d9778347 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 @@ -77,6 +77,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; +import org.springframework.util.ReflectionUtils; /** * Abstract implementation of the {@link org.springframework.context.ApplicationContext} @@ -867,13 +868,15 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } /** - * Reset Spring's common core caches, in particular the {@link ResolvableType} - * and the {@link CachedIntrospectionResults} caches. + * Reset Spring's common core caches, in particular the {@link ReflectionUtils}, + * {@link ResolvableType} and {@link CachedIntrospectionResults} caches. * @since 4.2 + * @see ReflectionUtils#clearCache() * @see ResolvableType#clearCache() * @see CachedIntrospectionResults#clearClassLoader(ClassLoader) */ protected void resetCommonCaches() { + ReflectionUtils.clearCache(); ResolvableType.clearCache(); CachedIntrospectionResults.clearClassLoader(getClassLoader()); } diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index cfd4bc9adf..acd36a2151 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -739,6 +739,15 @@ public abstract class ReflectionUtils { }, COPYABLE_FIELDS); } + /** + * Clear the internal method/field cache. + * @since 4.2.4 + */ + public static void clearCache() { + declaredMethodsCache.clear(); + declaredFieldsCache.clear(); + } + /** * Action to take on each method.