spring使用Redis自定义前缀后缀名(去掉SimpleKey []+自定义)
spring中自动加上 SimpleKey [] 解决方案

一、自定义后缀名
1、定义类实现KeyGenerator接口
MyKeyGenerator
package com.wbg.springRedis.service.impl;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method; @Component("myKeyGenerator")
public class MyKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object target, Method method, Object... params) {
//返回后缀名
//return method.getName(); //注意,这里不能返回null,否则会报错
//java.lang.IllegalArgumentException:
// Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.List com.wbg.springRedis.service.impl.RoleServiceImpl.listAll()] caches=[listAll] | key='' | keyGenerator='myKeyGenerator' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
return "";
}
}
2、注解使用:
@Cacheable(value = "listAll", keyGenerator = "myKeyGenerator")

已经解决

二、自定义前缀:
@Bean
RedisCacheManager cacheManager() { RedisCacheConfiguration configuration = RedisCacheConfiguration
.defaultCacheConfig()
.computePrefixWith(cacheName -> "redis" + cacheName)
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.java())); return RedisCacheManager.builder(redisConnectionFactory()).cacheDefaults(configuration).build();
}

spring使用Redis自定义前缀后缀名(去掉SimpleKey []+自定义)的更多相关文章
- Spring MVC 以.html为后缀名访问获取数据,报406 Not Acceptable错误。
如题,最近以spring mvc作为后台框架,前端异步获取数据时(.html为后缀名的访问方式),报406 Not Acceptable错误.当初都不知道啥原因,前后台都没报错就是返回不了数据,于是查 ...
- Spring MVC 以.html为后缀名访问获取数据,报406 Not Acceptable错误
转载,感谢这位博主,有自己的添加. 如题,最近以spring mvc作为后台框架,前端异步获取数据时(.html为后缀名的访问方式),报406 Not Acceptable错误.当初都不知道啥原因,前 ...
- 如何让Composer的autoload支持自定义文件后缀名
PHP的Composer工具规范了我们对系统各种资源库的加载格式,借助于PHP的自动加载机制,可以很大程度上简化在应用开发过程中的类库文件引用场景.但到目前为止,它有个不是问题的问题,就是文件后缀名只 ...
- WIN7/XP用注册表关联指定后缀名和打开程序(手动【图文】和C编程两种实现)
前言: 本文是基本原理介绍和手动的操作.程序实现该功能在http://blog.csdn.net/arvon2012/article/details/7839556,同时里面有完整代码的下载. 今天在 ...
- ubuntu下如何批量修改文件后缀名
正确的方法是: 在命令行中输入 rename 's/\.JPG/.jpg/' *.JPG [注意] 在单引号中的最后一个'/'符号不能少! 意思是:把当前文件夹下的所有 .JPG文件 替 ...
- ref:ubuntu下如何批量修改文件后缀名
ref:https://blog.csdn.net/whuslei/article/details/6724900 ubuntu下如何批量修改文件后缀名 正确的方法是: 在命令行中输入 renam ...
- 指定文件夹 指定文件后缀名 删除整个文件夹 git 冲突解决 create a new repository on the command line push an existing repository from the command line
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840038939c2 ...
- Struts2.0 去掉action后缀名
刚刚接触Struts2.0,发现默认请求都会带着后缀名:action 就如下图,url地址中会暴露login.action(请原谅struts拼写错误..) 作为一个URL简洁爱(chu)好(nv)者 ...
- [原创]Windows下更改特定后缀名以及特定URL前缀的默认打开方式
Windows下,特定后缀名的文件会由特定的应用程序来运行,比如双击readme.txt,通常情况下会由Windows自带的notepad.exe(记事本)打开文件.如果现在安装了记事本以外的其他文本 ...
随机推荐
- Rabbit简单队列模式
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/ ...
- springboot项目部署到独立tomcat的爬坑集锦
目录 集锦一:普通的springboot项目直接部署jar包 集锦二:springboot项目不能直接打war包部署 集锦三:因为tomcat版本问题导致的lombok插件报错:Invalid byt ...
- Uva 1378 - A Funny Stone Game
1378 - A Funny Stone Game Time limit: 3.000 seconds The funny stone game is coming. There are n pile ...
- 小白学flask之路由,反向路由,路由参数
# -*- coding: utf-8 -*- from flask import Flask, request, url_for app = Flask(__name__) @app.route(& ...
- Python入门-装饰器初始
今天我们就围绕一个来展开,那就是:装饰器 一.装饰器 在说装饰器之前,我们先说一个软件设计的原则:开闭原则,又被称为开放封闭原则,你的代码对功能的扩展是开放的,你的程序对修改源代码是封闭的,这样的软件 ...
- Angular的生命周期钩子
没有什么不能用一张图来解决.
- 解决github访问过慢问题
解决github访问过慢问题 主要原因: DNS 自动解析较慢 http://github.global.ssl.fastly.net.ipaddress.com/#ipinfo 用文本编辑器打开ho ...
- 深入理解token
链接:https://my.oschina.net/jamesfancy/blog/1613994 摘要: Token 是在服务端产生的.如果前端使用用户名/密码向服务端请求认证,服务端认证成功, ...
- linux crontab 的使用
linux crontab 的使用 准备(实验楼需要,实际环境不需要):sudo service rsyslog startsudo cron -f & crontab 使用添加任务:cron ...
- C# FTP操作类(获取文件和文件夹列表)
一.如何获取某一目录下的文件和文件夹列表. 由于FtpWebRequest类只提供了WebRequestMethods.Ftp.ListDirectory方式和WebRequestMethods.Ft ...