背景
SpringCloudAlibaba 负载均衡从ribbon替换成spring-cloud-loadbalancer 过程中出现警告:
报错信息
2021-08-18 18:42:55.841 INFO 31065 --- [ main] c.a.c.s.g.s.SentinelSCGAutoConfiguration : [Sentinel SpringCloudGateway] register SentinelGatewayBlockExceptionHandler
2021-08-18 18:42:56.026 INFO 31065 --- [ main] t.m.m.autoconfigure.MapperCacheDisabler : Clear tk.mybatis.mapper.util.MsUtil CLASS_CACHE cache.
2021-08-18 18:42:56.027 INFO 31065 --- [ main] t.m.m.autoconfigure.MapperCacheDisabler : Clear tk.mybatis.mapper.genid.GenIdUtil CACHE cache.
2021-08-18 18:42:56.027 INFO 31065 --- [ main] t.m.m.autoconfigure.MapperCacheDisabler : Clear tk.mybatis.mapper.version.VersionUtil CACHE cache.
2021-08-18 18:42:56.028 INFO 31065 --- [ main] t.m.m.autoconfigure.MapperCacheDisabler : Clear EntityHelper entityTableMap cache.
2021-08-18 18:42:56.438 WARN 31065 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2021-08-18 18:42:56.904 INFO 31065 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 9070
2021-08-18 18:42:56.945 INFO 31065 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP gsch-gateway-server 192.168.100.26:9070 register finished
2021-08-18 18:42:56.976 INFO 31065 --- [ main] c.z.gsch.gateway.GschGatewayApplication : Started GschGatewayApplication in 5.499 seconds (JVM running for 6.222)
解决方案
Add the below library in your pom.xml
<!-- https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.8</version>
</dependency>
or in your build.gradle
// https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine
compile group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.8'
You can replace the suitable/latest version of caffeine.
什么是 Caffeine Cache?
请参考以下几篇文章
Caffeine Cache实战
https://www.jianshu.com/p/3434991ad075
深入解密来自未来的缓存-Caffeine
https://juejin.cn/post/6844903670014803981
[译] 高性能 Java 缓存库 — Caffeine
https://juejin.cn/post/6844903506223038477
参考
升级 Spring Boot、Cloud 版本记录
http://dudu88.cn/2020/06/20/upgrade-spring-version-record/
How to solve "Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache’ warning?
https://stackoverflow.com/questions/65227645/how-to-solve-spring-cloud-loadbalancer-is-currently-working-with-the-default-ca