将 Azure Cache for Redis 连接到 Azure Spring Apps 中的应用程序

注意

Azure Spring Apps 是 Azure Spring Cloud 服务的新名称。 虽然该服务有新名称,但一些地方仍会使用旧名称,我们仍在更新屏幕截图、视频和图形等资产。

可以通过 Azure Spring Apps 将所选 Azure 服务自动连接到应用程序,而不必手动配置 Spring Boot 应用程序。 本文介绍如何将应用程序连接到 Azure Redis 缓存。

先决条件

  • 部署的 Azure Spring Apps 实例
  • Azure Redis 缓存服务实例
  • 用于 Azure CLI 的 Azure Spring Apps 扩展

如果没有已部署的 Azure Spring Apps 实例,请按照快速入门:将第一个应用程序部署到 Azure Spring Apps 中的步骤操作。

准备项目

  1. 在项目的 pom.xml 文件中,添加以下依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
    </dependency>
    
  2. 从 application.properties 文件中,删除所有 spring.redis.* 属性

  3. 使用 az spring app update 更新当前部署,或者使用 az spring app deployment create 创建新的部署。

将应用连接到 Azure Cache for Redis

后续步骤

本文介绍了如何将 Azure Spring Apps 中的应用程序连接到 Azure Cache for Redis。 若要详细了解如何将服务连接到应用程序,请参阅连接到 Azure Database for MySQL 实例