cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public



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作為屬性解析


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM