将 Azure Database for MySQL 实例连接到 Azure Spring Apps 中的应用程序

注意

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

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

先决条件

准备项目

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId>
    </dependency>
    
  2. 在 application.properties 文件中,删除所有 spring.datasource.* 属性。

  3. 通过运行 az spring app deploy 更新当前应用,或者通过运行 az spring app deployment create 针对此更改创建新的部署。

将应用连接到 Azure Database for MySQL 实例

后续步骤

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