如何解决“Spring Cloud LoadBalancer 目前正在使用默认缓存。您可以切换到使用 Caffeine 缓存”警告?

问题描述 投票:0回答:4

如何解决Spring Boot中的

Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it to the classpath.
警告?

java spring-boot caffeine caffeine-cache
4个回答
8
投票

将以下库添加到您的

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>

或者在你的

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'

您可以更换合适/最新版本的

caffeine


3
投票

Spring Boot:在

pom.xml
中添加以下依赖项就足够了:

<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>

0
投票

尝试将以下库添加到您的

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>



0
投票

根据文档,Spring 使用临时缓存,这对于原型设计和测试非常有用。

虽然基本的非缓存实现对于原型设计和测试很有用,但它的效率比缓存版本低得多,因此我们建议在生产中始终使用缓存版本。如果缓存已由

DiscoveryClient
实现完成,例如
EurekaDiscoveryClient
,则应禁用负载均衡器缓存以防止双重缓存。

所以最好有一个像咖啡因缓存这样更好的生产缓存机制。您只需在

pom.xml
build.gradle
中添加依赖项即可。 Spring将根据类路径依赖自动配置缓存。

<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
© www.soinside.com 2019 - 2024. All rights reserved.