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的值,名字随意。

  • 相关阅读:
    6.8
    6.7
    6.2
    6.1儿童节
    5.24
    5.22
    5.18
    5.17
    Visual Studio开始一个HelloWorld的enclave程序
    以太坊MPT树的HP(Hex-Prefix)编码
  • 原文地址:https://www.cnblogs.com/nieaojie625/p/13764496.html
Copyright © 2011-2022 走看看