当前位置:网站首页>子模块cache缓存失效
子模块cache缓存失效
2022-07-27 00:50:00 【CSDN问答】
问题遇到的现象和发生背景
在多模块的项目当中,使用注解的形式进行redis缓存,主模块的项目正常缓存,子模块的项目@Cacheable注解失效了。
问题相关代码,请勿粘贴截图
model-starter(主模块,负责启动项目与配置redis缓存)正常缓存
Application
starter
RedisConfig
@EnableCachingpublic class RedisConfig extends CachingConfigurerSupport { @Bean public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { RedisTemplate<String, Object> template = new RedisTemplate<>(); RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); template.setConnectionFactory(factory); //key序列化方式 template.setKeySerializer(redisSerializer); //value序列化 template.setValueSerializer(jackson2JsonRedisSerializer); //value hashmap序列化 template.setHashValueSerializer(jackson2JsonRedisSerializer); return template; } @Bean public CacheManager cacheManager(RedisConnectionFactory factory) { RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); //解决查询缓存转换异常的问题 ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); // 配置序列化(解决乱码的问题),过期时间600秒 RedisCacheConfiguration config = RedisCacheConfiguration .defaultCacheConfig() .entryTtl(Duration.ofSeconds(600)) .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)) .disableCachingNullValues(); RedisCacheManager cacheManager = RedisCacheManager.builder(factory) .cacheDefaults(config) // 可以给每个cacheName不同的RedisCacheConfiguration 设置不同的过期时间 //.withCacheConfiguration("Users",config.entryTtl(Duration.ofSeconds(100))) .transactionAware() .build(); return cacheManager; }}ServiceImpl
@Cacheable("name")getName(String name)model-common 缓存失效
ServiceImpl
@Cacheable("name")getName(String name)运行结果及报错内容
启动模块正常缓存,子模块没有进行缓存,而是每次都直接访问书库
我的解答思路和尝试过的方法
我尝试在RedisConfig中添加componentScan(“cn.com”)
无效
子模块的包扫描类中添加该package
继承 ImportBeanDefinitionRegistrar
无效
我想要达到的结果
不管是子模块还是主模块都能达到通过@Cacheable注解将数据缓存的redis
边栏推荐
- 1.28亿美元!芬兰量子计算公司IQM获世界基金支持
- Worth more than 100 million! The 86 version of "red boy" refuses to be a Daocheng Xueba. He is already a doctor of the Chinese Academy of Sciences and has 52 companies under his name
- [栈和队列简单题] LeetCode 232. 用栈实现队列,225. 用队列实现栈
- Time module: acquisition and mutual transformation of timestamp, structured time and formatted time
- cocos小游戏实战-05-NPC与角色攻击逻辑
- 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
- 2649: 段位计算
- Non global function of lua function
- Quick sort
- 批量复制宝贝上传提示乱码,如何解决?
猜你喜欢

window对象的常见事件

The EXE compiled by QT is started with administrator privileges

After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized

Lua函数之非全局函数

A math problem cost the chip giant $500million!

196. 删除重复的电子邮箱

Portraiture5全新升级版磨皮滤镜插件神器

红宝书第四版的一个错误?

身家破亿!86版「红孩儿」拒绝出道成学霸,已是中科院博士,名下52家公司

Ten thousand words long text, take you to understand the kubernetes network model
随机推荐
从ACL 2022 Onsite经历看NLP热点
Favicon网页收藏图标在线制作PHP网站源码/ICO图片在线生成/支持多种图片格式转换
177. 第N高的薪水(简单)
素因子分解--C(gcc)--PTA
阿里云解决方案架构师张平:云原生数字化安全生产的体系建设
Knowledge points of test questions related to software testing
Social wechat applet of fanzhihu forum community
小玩一个并行多线程MCU—MC3172
Redis四大特殊数据类型的学习和理解
制作ppt时间轴
How to visit the latest version of burpsuite pro in vain
After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized
基于GoLang实现API短信网关
[dynamic planning medium] leetcode 198. looting 740. delete and get points
Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
IDEA 连接数据库查询数据后控制台表头中文乱码的解决方法
[动态规划简单题] LeetCode 53. 最大子数组和
Debezium系列之:基于debezium offset拉取历史数据,确保数据没有丢失
LabVIEW中编程更改进程的优先级
iNFTnews | GGAC联合中国航天ASES 独家出品《中国2065典藏版》