Share via


使用 IntelliJ 部署 Spring Boot 應用程式

注意

Azure Spring Apps 是 Azure Spring Cloud 服務的新名稱。 雖然服務有新的名稱,但在我們努力更新資產,例如螢幕快照、影片和圖表時,您會在某些地方看到舊名稱一段時間。

本文適用於: ✔️ Java ❌ C#

本文適用於: ✔️基本/標準✔️企業

適用於 Azure Spring Apps 的 IntelliJ 外掛程式支援從 IntelliJ IDEA 部署應用程式。

執行此範例之前,您可以嘗試 基本快速入門

必要條件

安裝外掛程式

您可以從 IntelliJ 外掛程式 UI 新增適用於 IntelliJ IDEA 3.51.0 的 Azure 工具組

  1. 啟動 IntelliJ。 如果您先前已開啟專案,請關閉專案以顯示歡迎對話方塊。 從右下方的連結選取 [ 設定 ],然後選取 [外掛程式 ] 以開啟外掛程式組態對話框,然後選取 [ 從磁碟安裝外掛程式]。

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

  2. 搜尋適用於 IntelliJ 的 Azure 工具組。 選取安裝

    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 Explorer],然後選取 [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.

下一步