当前位置:网站首页>Submodule cache cache failure
Submodule cache cache failure
2022-07-27 03:16:00 【CSDN Q & A】
The phenomenon and background of the problem
In a multi module project , Use the form of annotations redis cache , The project of the main module is cached normally , Sub module items @Cacheable The annotation is invalid .
Problem related code , Do not paste screenshots
model-starter( The main module , Be responsible for starting the project and configuration redis cache ) Normal cache
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 Serialization mode template.setKeySerializer(redisSerializer); //value serialize template.setValueSerializer(jackson2JsonRedisSerializer); //value hashmap serialize template.setHashValueSerializer(jackson2JsonRedisSerializer); return template; } @Bean public CacheManager cacheManager(RedisConnectionFactory factory) { RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); // Solve the problem of query cache conversion exception ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); // Configure serialization ( Solve the problem of garbled code ), Expiration time 600 second 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) // You can give it to each cacheName Different RedisCacheConfiguration Set different expiration times //.withCacheConfiguration("Users",config.entryTtl(Duration.ofSeconds(100))) .transactionAware() .build(); return cacheManager; }}ServiceImpl
@Cacheable("name")getName(String name)model-common Cache invalidation
ServiceImpl
@Cacheable("name")getName(String name)Operation results and error reporting contents
Start the normal cache of the module , The sub module is not cached , Instead, you visit the library directly every time
My solution ideas and tried methods
I'm trying to RedisConfig Add componentScan(“cn.com”)
Invalid
Add this... To the package scanning class of the sub module package
Inherit ImportBeanDefinitionRegistrar
Invalid
What I want to achieve
Both sub modules and main modules can pass @Cacheable Annotations cache data redis
边栏推荐
- 制作ppt时间轴
- 浅浅梳理一下双轴快排(DualPivotQuickSort)
- 软件测试面试常见问题及答案(发散思维、接口、性能、概念、)
- FactoryBean的getObject调用时机
- sqlserver select * 能不能排除某个字段
- opiodr aborting process unknown ospid (21745) as a result of ORA-609
- [二分查找简单题] LeetCode 35. 搜索插入位置,69. x 的平方根,367. 有效的完全平方数,441. 排列硬币
- 积分发放带给商家的两个帮助
- 175. Combine two tables (very simple)
- Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
猜你喜欢
软件测试面试常见问题及答案(发散思维、接口、性能、概念、)

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

Make ppt timeline

On the prototype of constructor

Worthington果胶酶的特性及测定方案

Use the most primitive method to manually implement the common 20 array methods

论构造函数的原型是谁

图解 SQL,这也太形象了吧!
![Analysis of [paper] pointlanenet papers](/img/f6/8001be4f90fe15100e0295de02491f.png)
Analysis of [paper] pointlanenet papers

商城小程序项目完整源码(微信小程序)
随机推荐
在线问题反馈模块实战(十五):实现在线更新反馈状态功能
Naive Bayes -- Document Classification
How to visit the latest version of burpsuite pro in vain
阿里云技术专家杨泽强:弹性计算云上可观测能力的构建
pip3 设置阿里云
[paper]PointLaneNet论文浅析
[动态规划简单题] LeetCode 53. 最大子数组和
队列达到最大长度代码实战
力扣(LeetCode)207. 课程表(2022.07.26)
排列与二进制(吉,大)(DAY 84)
[binary search simple question] leetcode 35. search insertion position, 69. Square root of X, 367. Effective complete square, 441. Arrange coins
二叉树(北京邮电大学机试题)(DAY 85)
[SQL简单题] LeetCode 627. 变更性别
impala 执行计划详解
一体式水利视频监控站 遥测终端视频图像水位水质水量流速监测
vector 转 svg 方法
Complete source code of mall applet project (wechat applet)
商城小程序项目完整源码(微信小程序)
Baidu cloud face recognition
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