zoukankan      html  css  js  c++  java
  • SpringBoot使用缓存报错java.lang.IllegalStateException: No cache could be resolved for 'Builder[public com.example.bean.Employee

    SpringBoot使用缓存报错java.lang.IllegalStateException: No cache could be resolved for 'Builder[public com.example.bean.Employee

    报错如下:

    java.lang.IllegalStateException: No cache could be resolved for 'Builder[public com.example.bean.Employee com.example.controller.EmployeeController.getEmpById(java.lang.Integer)] caches=[] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'' using resolver 'org.springframework.cache.interceptor.SimpleCacheResolver@540d3d5d'. At least one cache should be provided per cache operation.

    解决方法:

    1、在SpringBoot启动类上添加@EnableCaching注解。

    2、在controller中需要加入缓存的方法中添加@Cacheable,需要指定cacheNames缓存组件的名称。

    @Cacheable(cacheNames = "emp")
    @GetMapping("/getEmpById/{id}")
    public Employee getEmpById(@PathVariable("id") Integer id) {
        return employeeService.getEmpById(id);
    }
    

    例如上面需要指定cacheNames的值,名字随意。

  • 相关阅读:
    GCD (hdu 5726)
    1092
    D. Puzzles(Codeforces Round #362 (Div. 2))
    A. Lorenzo Von Matterhorn
    Polyomino Composer(UVA12291)
    Optimal Symmetric Paths(UVA12295)
    菜鸟物流的运输网络(计蒜客复赛F)
    1193
    1119
    1374
  • 原文地址:https://www.cnblogs.com/nieaojie625/p/13764496.html
Copyright © 2011-2022 走看看