【问题标题】:Problem in configuring spring boot and redis配置spring boot和redis的问题
【发布时间】:2019-12-01 21:35:56
【问题描述】:

我有一个旧的 Spring Boot 应用程序(1.5.0-FINAL),我无法更改此版本。 我想将 redis 添加到我的应用程序中,这就是我所做的:

1) 添加了maven dep:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
        <version>1.5.10.RELEASE</version>
    </dependency>

2) 将属性添加到我的引导中

@EnableCaching
public class MySpringBootApp{

3) 添加配置属性以检查是否启动连接:

spring.cache.type: redis
spring.redis.host: 192.168.99.100
spring.redis.port: 6379

上面的主机/端口不存在:我只想在启动时看到类似“连接错误”的信息,以确保我配置了所有内容但没有出现!看来spring boot只是不尝试使用缓存。

我错过了什么吗?也许我的 Spring Boot 版本太旧了?

【问题讨论】:

    标签: spring-boot redis spring-data-redis


    【解决方案1】:

    Spring Boot parent pom 已经定义了启动器的版本,所以从 spring-boot-starter-data-redis 依赖中删除版本。

    你的 pom.xml 至少会有这些依赖。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <type>pom</type>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    

    接下来,@EnableCaching 将查找带有@Cacheable 或@CachePut 注解的bean。

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-02
      • 1970-01-01
      相关资源
      最近更新 更多