当前位置:网站首页>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
边栏推荐
- 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
- [dynamic programming simple question] leetcode 53. maximum subarray and
- Worthington果胶酶的特性及测定方案
- 177. The nth highest salary (simple)
- 如何使用DevExpress WPF在WinUI中创建第一个MVVM应用程序?
- MarqueeView实现滑动展示效果
- Acwing 2074. Countdown simulation
- A math problem cost the chip giant $500million!
- 【flask】服务端获取客户端请求的文件
- 2649: segment calculation
猜你喜欢

Inftnews | "traffic + experience" white lining e Digital Fashion Festival leads the new changes of digital fashion

Redis四大特殊数据类型的学习和理解

在线问题反馈模块实战(十五):实现在线更新反馈状态功能

Social wechat applet of fanzhihu forum community

How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?

次轮Okaleido Tiger即将登录Binance NFT,引发社区热议

字节一面:TCP 和 UDP 可以使用同一个端口吗?

CAS部署使用以及登录成功跳转地址

Complete source code of mall applet project (wechat applet)

Attention should be paid to the first parameter of setTimeout
随机推荐
Alibaba cloud technology expert Yang Zeqiang: Construction of observability on elastic computing cloud
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
OC-消息机制
在线问题反馈模块实战(十五):实现在线更新反馈状态功能
Thread.Sleep(0)的作用
Best practices of opentelemetry in service grid architecture
二叉树(DAY 82)
How to use devaxpress WPF to create the first MVVM application in winui?
自己梳理的LocalDateTime的工具类
制作ppt时间轴
【flask】服务端获取客户端的请求头信息
队列达到最大长度代码实战
Call jshaman's Web API interface to realize JS code encryption.
字节一面:TCP 和 UDP 可以使用同一个端口吗?
The most complete basic knowledge of software testing in the whole network (a must for beginners)
Analysis of [paper] pointlanenet papers
图解 SQL,这也太形象了吧!
批量复制宝贝上传提示乱码,如何解决?
Functions that should be selected for URL encoding and decoding
Oracle有没有分布式数据库?