社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Redis

尝试使用spring boot在redis缓存中插入数据时,出现一些运行时错误

Ravi Singh Shekhawat • 4 年前 • 442 次点击  

尝试通过redis缓存检索数据时出现以下错误: 为缓存操作返回的空键(可能您正在没有调试信息的类上使用命名参数?)生成器[public java.util.list com.concretepage.celebcontroller.getall()]缓存=[celebcache]键='p1'键生成器=''''缓存管理器='''''缓存解析程序=''条件='''''124;除非='''''sync='false']有根本原因

已尝试通过将cachekey重命名为p0来解决类似类型的其他问题,但仍面临相同的错误。

型号:

import javax.persistence.*;

@Entity(name="celeb")
public class Celeb {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private long id;
    @Column(name="celeb_name")
    private String name;
    @Column(name="no_of_followers")
    private long followers;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getFollowers() {
        return followers;
    }

    public void setFollowers(long followers) {
        this.followers = followers;
    }

    @Override
    public String toString() {
        return "Celeb{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", followers=" + followers +
                '}';
    }
}

模型控制器:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CelebController {

    Logger logger = LoggerFactory.getLogger("CelebController");

    @Autowired
    private CelebRepository celebRepository;


    @PostMapping("/create")
    public void createUser(@RequestBody Celeb user) {
        celebRepository.save(user);
    }

    @Cacheable(value = "celebcache", key = "#p0")
    @GetMapping("/getall")
    public List<Celeb> getAll() {

        logger.info("Returning from DB");
        return celebRepository.findAll();

    }

    @PostMapping("/delete")
    public void createUser(@RequestParam(value = "userid")Integer id) {
        celebRepository.deleteById(id);
    }


}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43677
 
442 次点击  
文章 [ 1 ]  |  最新文章 4 年前