cannot be found on object of type xx.CacheExpressionRootObject
0 环境
- 系统环境:win10
- 编辑器:IDEA
1 前言->环境搭建
1-1 pom依赖
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.8.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>org.javaboy</groupId>
- <artifactId>chapter09-cacheredis</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>chapter09-cacheredis</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-cache</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
1-2 properties(redis的基本配置以及缓存名的配置)
- spring.redis.host=127.0.0.1
- spring.redis.password=123456
- spring.redis.port=6379
- spring.redis.database=0
- spring.cache.cache-names=c1
1-3 Application启动项添加
1-4 自定义KeyGenerator
- @Component
- public class MyKeyGen implements KeyGenerator {
- @Override
- public Object generate(Object o, Method method, Object... objects) {
- return method.getName()+":"+ Arrays.toString(objects);
- }
1-5 service层
- @Service
- //@CacheConfig(cacheNames = "c1")
- public class BookService {
- // key = "#methodName"
- // key = "#method.name"
- // key = "#caches[0]"
- // key = "#args[0]"
- // @Cacheable(cacheNames = "c1",key = "#caches[0]")
- @Cacheable(cacheNames = "c1",key = "'myKeyGen'")
- public Book getUserById(Integer id){
- System.out.println("book>>>>>>" + id);
- Book book = new Book();
- book.setId(id);
- return book;
- }
- }
1-6 单元测试
- @Autowired
- BookService bookService;
- @Test
- public void contextLoads() {
- Book book = bookService.getUserById(1);
- Book book1 = bookService.getUserById(1);
- System.err.println("book --->>" + book);
- System.err.println("book1 --->>" + book1);
- }
2 报错
- key = "''" (需要内嵌一下单引号 不然会报错)
cannot be found on object of type xx.CacheExpressionRootObject的更多相关文章
- PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)
php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误:Cannot use object of type stdClass as arra ...
- PHP json_decode object时报错Cannot use object of type stdClass as array
PHP json_decode object时报错Cannot use object of type stdClass as array php再调用json_decode从字符串对象生成json对象 ...
- MyBatis Generator报错:Cannot instantiate object of type
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate ( ...
- spring boot 之 错误:SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap'
这个错误我也见过很多次了,今天终于理解了其出现的原因. 错误是这样的: 2017-11-23 18:05:39.504 ERROR 4092 --- [nio-8080-exec-3] o.a.c.c ...
- Unable to cast object of type 'System.Int32' to type 'System.Array'.
x 入职了新公司.最近比较忙...一看博客...更新频率明显少了...罪过罪过... 新公司用ASP.NET MVC 遇上一个错误: Unable to cast object of type 'Sy ...
- iwebshop (: Cannot use object of type stdClass as array in)
今天在PHP输出一个二维数组的时候,出现了“Fatal error: Cannot use object of type stdClass as array in……”. 这个二维数组是这样的: Ar ...
- celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式
#python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...
- Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化
Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
随机推荐
- java.io.tmpdir在哪里?
查找所在目录的方式如下: System.out.println(System.getProperty(“java.io.tmpdir”)); System.getProperty(),还可以获取更多其 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: DOM 事件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- tensorflow 损失计算--MSN
1.tf.losses.mean_squared_error函数 tf.losses.mean_squared_error( labels, predictions, weights=1.0, sco ...
- GaussDB数据dump实现完全同步
问题背景:搭建服务后端容灾集群,服务正常时容灾DB需要从业务DB完全同步数据,服务异常时,容灾DB停止抽取数据,自动从探针采集业务数据. 解决方案:常用的有两种思路,一是从服务后端定时每天拉取业务DB ...
- 将hello程序作为驱动程序编译进系统内核
0x00开始 恩,可能是我比较愚钝,一个内核编译搞了一天,各种问题,各种bug,几度无奈,也是因为我突发奇想,并没有按照原来的那种操作,我直接把helloworld程序放到内核模块中编译成了一个驱动程 ...
- Django模型基础(三)——关系表的数据操作
模型之间可以有三种表关系,即一对一,一对多和多对多.表关联之间的数据操作在Django中可以很方便的操作到.在模型中,表关联的字段类型是关联表的实例,而不是字段本身类型.关联字段在数据库中会在其后补上 ...
- Codeforces Round #568 (Div. 2)网卡&垫底记
这场和div3差不多嘛(后来发现就是div3),就是网太卡10min交一发就不错了,简直自闭. A 签到. B 记录每一段的字母数,满足条件即:段数相同+字母相同+字母数下>=上. #inclu ...
- 1. react 基础 简介 及 环境搭建
一.简介 由 Facebook 推出 2013 年 开源 的 函数式编程的 使用人数最多的 前端框架 拥有健全的文档与完善的社区 ( 官网 ) react 16 称为 React Fiber ( 底层 ...
- 题解 P1829 【[国家集训队]Crash的数字表格 / JZPTAB】
题目 我的第一篇莫比乌斯反演题解 兴奋兴奋兴奋 贡献一个本人自己想的思路,你从未看到过的船新思路 [分析] 显然,题目要求求的是 \(\displaystyle Ans=\sum_{i=1}^n\su ...
- 一、早期(Early Stage)
一.早期(Early Stage) 如果单纯从零基础开始,早期(Early Stage)应该是一到两个月(由于英语与中文差异比与其他语言大,中国同学至少两个月,但也不应过长.我们的经验是一般中国同学会 ...