你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 IntelliJ 部署 Spring Boot 应用程序

注意

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

本文适用于:✔️ Java C#

本文适用于: ✔️ 基本版/标准版 ✔️ 企业版

适用于 Azure Spring Apps 的 IntelliJ 插件支持从 IntelliJ IDEA 进行应用程序部署。

在运行此示例之前,可以尝试基础知识快速入门

先决条件

安装插件

可以从 IntelliJ“插件”UI 添加 Azure Toolkit for IntelliJ IDEA 3.51.0。

  1. 启动 IntelliJ。 如果以前打开过某个项目,请关闭该项目以显示“欢迎”对话框。 从右下方的链接中选择“配置”,然后选择“插件”以打开插件配置对话框,然后选择“从磁盘安装插件” 。

    Screenshot of IntelliJ IDEA Welcome dialog box with Configure element highlighted.

  2. 搜索“Azure Toolkit for IntelliJ”。 选择“安装” 。

    Screenshot of IntelliJ IDEA Plugins dialog box with Install button highlighted.

  3. 选择“重启 IDE”。

教程过程

以下过程使用 IntelliJ IDEA 部署 Hello World 应用程序。

  • 打开 gs-spring-boot 项目
  • 部署到 Azure Spring Apps
  • 显示流式处理日志

打开 gs-spring-boot 项目

  1. 下载本教程的源存储库并将其解压缩,或使用以下 Git命令克隆它:git clone https://github.com/spring-guides/gs-spring-boot.git

  2. 导航到 gs-spring-boot\complete 文件夹。

  3. 打开 IntelliJ 的“欢迎”对话框,选择“导入项目”以打开导入向导 。

  4. 选择 gs-spring-boot\complete 文件夹。

    Screenshot of IntelliJ IDEA Open File or Project dialog box with complete folder highlighted.

部署到 Azure Spring Apps

若要部署到 Azure,必须使用你的 Azure 帐户登录,然后选择你的订阅。 有关登录的详细信息,请参阅安装和登录

  1. 在 IntelliJ 项目资源管理器中右键单击你的项目,选择“Azure”->“部署到 Azure Spring Apps”。

    Screenshot of IntelliJ IDEA context menu with Deploy to Azure Spring Apps option highlighted.

  2. 在“名称”字段中接受应用的名称。 “名称”是指配置,不是应用名称。 用户通常不需更改它。

  3. 接受来自项目的标识符作为“生成工件”。

  4. 选择“应用:”,然后单击 + 以创建 Azure Spring Apps 实例。

    Screenshot of IntelliJ IDEA Deploy Azure Spring app dialog box with plus button highlighted.

  5. 输入“应用名称”,然后选择“确定” 。

    Screenshot of IntelliJ IDEA Create Azure Spring App dialog box with App name field in focus.

  6. 选择“运行”按钮,开始部署。

    Screenshot of IntelliJ IDEA showing Run button.

  7. 此插件会对项目运行命令 mvn package,然后创建新的应用并部署由 package 命令生成的 jar。

  8. 如果应用 URL 未显示在输出窗口中,请从 Azure 门户获取它。 从资源组导航到 Azure Spring Apps 实例。 然后选择“应用”。 将会列出正在运行的应用。 选择应用,然后复制“URL”或“测试终结点” 。

    Screenshot of Azure portal showing the app overview page with the URL and Test Endpoint fields highlighted.

  9. 在浏览器中导航到 URL 或测试终结点。

    Screenshot of the app running in a browser displaying the message Greetings from Spring Boot.

显示流式处理日志

若要获取日志,请执行以下操作:

  1. 依次选择“Azure 资源管理器”、“Spring Apps”。

  2. 右键单击正在运行的应用。

  3. 从下拉列表中选择“流日志”。

    Screenshot of IntelliJ IDEA context menu with the Streaming Log option highlighted.

  4. 选择实例。

    Screenshot of the IntelliJ IDEA Select Instance dialog box.

  5. 流式处理日志将显示在输出窗口中。

    Screenshot of the IntelliJ IDEA showing the streaming log in the output window.

后续步骤