首页 > 解决方案 > CachedIntrospectionResults - 不是强缓存类,因为它不是缓存安全的

问题描述

有谁知道这个警告是什么意思?

o.s.b.CachedIntrospectionResults - Not strongly caching class because it is not cache-safe

这是我的游戏框架应用程序中记录的警告。它似乎与春季的这门课有关,但我找不到更多信息......

标签: javaspringplayframeworkjavabeans

解决方案


似乎该消息是从库的方法中抛出的,该方法使用库的org.springframework.beans.CachedIntrospectionResults#forClass方法来检查指定的类是否是缓存安全的(它检查该类是否由与 CachedIntrospectionResults 类相同的类加载器加载)。spring-beansorg.springframework.util.ClassUtils#isCacheSafespring-core

CachedIntrospectionResults#forClass:

/**
* Create CachedIntrospectionResults for the given bean class.
* @param beanClass the bean class to analyze
* @return the corresponding CachedIntrospectionResults
* @throws BeansException in case of introspection failure
*/
static CachedIntrospectionResults forClass(Class<?> beanClass) {
    ...
    if (ClassUtils.isCacheSafe(...)) {
        ...
    }
    else {
        ...
        logger.debug("Not strongly caching class [" + beanClass.getName() + "] because it is not cache-safe");
    }
    ...
}

ClassUtils#isCacheSafe:

/**
* Check whether the given class is cache-safe in the given context,
* i.e. whether it is loaded by the given ClassLoader or a parent of it.
* @param clazz the class to analyze
* @param classLoader the ClassLoader to potentially cache metadata in
* (may be {@code null} which indicates the system class loader)
*/
public static boolean isCacheSafe(Class<?> clazz, @Nullable ClassLoader classLoader) {
...

也许CachedIntrospectionResultsClassUtils类的来源会澄清这个问题。


推荐阅读