美文网首页
cannot be found on object of typ

cannot be found on object of typ

作者: 万事俱备就差一个程序员了 | 来源:发表于2022-02-27 11:12 被阅读0次

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作为属性解析

相关文章

网友评论

      本文标题:cannot be found on object of typ

      本文链接:https://www.haomeiwen.com/subject/nhkhrrtx.html