How to solve Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it to the classpath.
warning in spring boot?
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
.
Spring Boot: Adding the following dependencies in the pom.xml
will be adequate:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
Try to add the below library in your pom.xml
.
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.3.19</version>
</dependency>
As per the documentation, spring usages adhoc cacheing which is useful for prototyping and testing.
Although the basic, non-cached, implementation is useful for prototyping and testing, it’s much less efficient than the cached versions, so we recommend always using the cached version in production. If the caching is already done by the
DiscoveryClient
implementation, for exampleEurekaDiscoveryClient
, the load-balancer caching should be disabled to prevent double caching.
So it's better to have a better caching mechanism for production like caffeine cache. You just have to add the dependency in your pom.xml
or build.gradle
. Spring will autoconfigure the cache based on the classpath dependency.
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.0</version> <!-- Use the latest version as appropriate -->
</dependency>
implementation 'com.github.ban-manes.caffeine:caffeine:2.9.0' // Use the latest version as appropriate
© 2022 - 2024 — McMap. All rights reserved.
spring.cloud.loadbalancer.cache.enabled=false
. See this reference chapter for details: docs.spring.io/spring-cloud-commons/docs/3.0.2/reference/html/… – Caviness