Class CachedIntrospectionResults

java.lang.Object
org.springframework.beans.CachedIntrospectionResults

public final class CachedIntrospectionResults extends Object
Internal class that caches JavaBeans PropertyDescriptor information for a Java class. Not intended for direct use by application code.

Necessary for Spring's own caching of bean descriptors within the application ClassLoader, rather than relying on the JDK's system-wide BeanInfo cache (in order to avoid leaks on individual application shutdown in a shared JVM).

Information is cached statically, so we don't need to create new objects of this class for every JavaBean we manipulate. Hence, this class implements the factory design pattern, using a private constructor and a static forClass(Class) factory method to obtain instances.

Note that for caching to work effectively, some preconditions need to be met: Prefer an arrangement where the Spring jars live in the same ClassLoader as the application classes, which allows for clean caching along with the application's lifecycle in any case.

As of 6.0, Spring's default introspection discovers basic JavaBeans properties through an efficient method reflection pass. For full JavaBeans introspection including indexed properties and all JDK-supported customizers, configure a META-INF/spring.factories file with the following content: org.springframework.beans.BeanInfoFactory=org.springframework.beans.StandardBeanInfoFactory For Spring 5.3 compatible extended introspection including non-void setter methods: org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory

Since:
05 May 2001
Author:
Rod Johnson, Juergen Hoeller
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.
    static void
    Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • acceptClassLoader

      public static void acceptClassLoader(@Nullable ClassLoader classLoader)
      Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.

      This configuration method is only relevant in scenarios where the Spring classes reside in a 'common' ClassLoader (for example, the system ClassLoader) whose lifecycle is not coupled to the application. In such a scenario, CachedIntrospectionResults would by default not cache any of the application's classes, since they would create a leak in the common ClassLoader.

      Any acceptClassLoader call at application startup should be paired with a clearClassLoader(java.lang.ClassLoader) call at application shutdown.

      Parameters:
      classLoader - the ClassLoader to accept
    • clearClassLoader

      public static void clearClassLoader(@Nullable ClassLoader classLoader)
      Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.
      Parameters:
      classLoader - the ClassLoader to clear the cache for