Cannot find cache named for Builder[public java.u Property or field cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public
key如果是常量必須用單引號引起來: key ="'keyStrijng'";
key拼接語法:
@Cacheable(value = "page_user",key ="T(String).valueOf(#page).concat('-').concat(#pageSize)",unless = "#result=null")//由於page是int型,concat要求變量必須為String,所以強轉一下
@Override
public List<SysUserEntity> page(int page, int pageSize) {
return userMapper.page(page,pageSize);
}
}
補充:記一個spring緩存Cacheable注解key設置問題
spring的Cacheable注解用來設置緩存,其中的key屬性為spel表達式,如果要設置常量,則需要用''包裹,如:
1
@Cacheable(value = CacheConstant.APPLICATION,key = "'id_map'")
此處的"'id_map'"代表key設置了一個常量,如果沒有'',則會報錯
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'lang_code_map' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public or not valid?
意思為在緩存表達式根對象上找不到指定屬性,說明如果不加'',則id_map作為屬性解析