关于springboot注解式开发缓存问题java.lang.IllegalStateException

在使用springboot中的注解缓存开发时;需要给cacheNames这个属性值,不然会抛出下面异常

  java.lang.IllegalStateException:org.java.service.impl.StudentServiceImpl.getStudentById(java.lang.Integer)] caches=[] | key='#id' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'' using resolver 
  'org.springframework.cache.interceptor.SimpleCacheResolver@5e434f02'. At least one cache should be provided per cache operation

@CachePut在使用的时候,需要注意,修改后在service层使用到的方法的返回值,需要返回的是一个对象,不然没有办法成功,会报错,(类型转化错误)
注意保证key的值是相同的, 注意update上的CachePut的key的值是 #result.id ,其中的result代表的就是返回的这个对象
service层

猜你喜欢

转载自blog.csdn.net/whiteGu/article/details/82292165