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报错 错 ...
随机推荐
- JDK8 API离线文档免费下载&JavaEE API文档离线下载&API在线查看链接&常用的JAR包下载
1.JDK8 API离线文档 链接:https://pan.baidu.com/s/1fYc-QesmYRumTEPmnSgEKA 提取码:2bdr 2.JavaEE API文档离线下载 链接:htt ...
- 初学者学习JavaScript的实用技巧!
Javascript是一种高级编程语言,通过解释执行.它是一门动态类型,面向对象(基于原型)的直译语言.它已经由欧洲电脑制造商协会通过ECMAScript实现语言标准化,它被世界上的绝大多数网站所使用 ...
- 吴裕雄--天生自然 PHP开发学习:数组排序
<?php $cars=array("Volvo","BMW","Toyota"); sort($cars); print_r($ca ...
- 【转帖】虚拟化Pod性能比裸机还要好,原因竟然是这样!
虚拟化Pod性能比裸机还要好,原因竟然是这样! http://www.itpub.net/2020/02/27/5340/ 其实感觉 linux也可以做到 NUMA的节点优化 其实 直接在 ESXi上 ...
- CMake变量(提供信息的变量)
目录 CMAKE_VERSION CMAKE_MAJOR_VERSION CMAKE_MINOR_VERSION CMAKE_PATCH_VERSION CMAKE_TWEAK_VERSION CMA ...
- CMS-熊海网站内容管理系统漏洞测试
开门见山 在虚拟机中搭建网站,本机访问http://192.168.31.68/ 一.SQL注入获取管理员账号密码 1. 点开一篇文章,存在get请求参数 2. 手工注入无果,使用sqlmap,后跟- ...
- 吴裕雄--天生自然Linux操作系统:Linux 云服务器
自己安装服务器还是麻烦了些,现在一般都推荐大家使用云服务器,比较方便,价格也不贵. 腾讯云 以下几款性价比非常高,有几款是需要抢购的,大家看好时间基本能拿到. 1.1核2G 99/年,可以用来学习,L ...
- node/静态路由/express框架中的express.static()和app.use()
此篇文章转载于 express框架中的express.static()和app.use() Express框架在使用app.use中传入express.static设置静态路由时,这个文件夹下的所有文 ...
- Python模块——json
简介 json全名是JavaScript Object Notation(即:Javascript对象标记).它是JavaScript的子集,JSON是轻量级的文本数据交换格式.前端和后端进行数据交互 ...
- i春秋web作业2.26
Web安全工程师(入门班) [全国线上入门班53期]课后作业 2020-2-26 DorinXL 1)为什么说js校验是一种不安全的校验方式? js校验不安全,是因为用户很容易通过控制台删除或 ...