Warning: The magic method InvisibleReCaptcha\MchLib\Plugin\MchBasePublicPlugin::__wakeup() must have public visibility in /home/c9138697/public_html/juncleit.com/wp-content/plugins/invisible-recaptcha/includes/plugin/MchBasePublicPlugin.php on line 37
Spring Boot Tips : Spring BootアプリケーションをAzure Web Appにデプロイ | マサトッシュブログ

Spring Boot Tips : Spring BootアプリケーションをAzure Web Appにデプロイ

AppService Plan

これまでSpring Bootアプリケーションをmavenを使ってビルドする方法を学習してきた。今度はサンプルのSpring Bootアプリケーションをローカルで実行するのではなく、AzureのWeb Appsにデプロイして実行する。

Spring Boot アプリを Azure App Service にデプロイする - Training
Spring Boot アプリケーションを作成し、MySQL データベースに接続してから、Azure App Service にデプロイします。

作成する手順は以下の通り

  1. Spring InitializrでMavenプロジェクトテンプレートを作成する
  2. サンプルJavaプログラム(Hello, WorldのREST)を作成してローカル環境で動作確認
  3. Azure CLIでサブスクリプションにリソースグループを作成する
  4. pom.xmlにAzure プラグインを指定して、mavenのビルドプロセスでAzure App Serviceを作成する
  5. mavenでサンプルjavaプログラムをビルドしてAzure App Serviceにデプロイ
  6. Azure App ServiceにデプロイしたサンプルJavaプログラムの動作確認

AzureリソースはCLIを使って作成する。デプロイするアプリケーションはいつもの簡単な「Hello, World」RESTサービスを用いる。

Spring Bootサンプルアプリケーションの作成

今回はプロジェクトファイルをSpring Initiaizrを使用したテンプレートで作成する。まずはローカルで動作確認してから、Azureリソースにデプロイして動作確認する。

Spring Initializrを使用したプロジェクトテンプレートの作成

今までゼロからpom.xmlやプロジェクトフォルダー構成を作成していたが、今回はWEBで利用できるSpring Initializrを使ってプロジェクトテンプレートを作成してから簡単なサンプルアプリケーションを作成する。

https://start.spring.io/

「Project Metadata」に分かりづらいパラメータがあるため以下に補足を記載する。

  • Group:作成するプログラム群が所属するグループ名。ドメインを持っている人は多分逆ドメイン名を用いるのが一番無難だと思う。pom.xmlの「groupId」に指定する文字列。
  • Artifact:作成するプログラム群の成果物名。プロジェクト名だろうな。pom.xmlの「artifactId」に指定する文字列。
  • Name:プロジェクトルートフォルダー名。artifactと同じ文字列で良いと思う。pom.xmlの「name」に指定する文字列。
  • Description:プロジェクトの説明文。pom.xmlの「description」に指定する文字列。
  • Package name:このプロジェクトに含めるJavaプログラムの名前空間名。Group+”.”+Artifact(小文字)で良いと思う。
  • Dependencies:このプロジェクトで必要となる外部ライブラリ。pom.xmlの「dependencies」に指定される。今回はSpring Webだけ必要。

上記を入力し、「GENERATE」をクリックすると「Artifact名.zip」というファイル名のプロジェクトテンプレートがダウンロードできる。

プロジェクトテンプレートの中身は以下の通り。

% tar tvfz AzureAppService.zip 
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/
-rw-r--r--  0 0      0         858  2  2 15:39 AzureAppService/HELP.md
-rw-r--r--  0 0      0         395  2  2 15:39 AzureAppService/.gitignore
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/java/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/java/com/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/java/com/example/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/java/com/example/azureappservice/
-rw-r--r--  0 0      0         338  2  2 15:39 AzureAppService/src/main/java/com/example/azureappservice/AzureAppServiceApplication.java
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/resources/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/resources/templates/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/main/resources/static/
-rw-r--r--  0 0      0           1  2  2 15:39 AzureAppService/src/main/resources/application.properties
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/test/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/test/java/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/test/java/com/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/test/java/com/example/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/src/test/java/com/example/azureappservice/
-rw-r--r--  0 0      0         228  2  2 15:39 AzureAppService/src/test/java/com/example/azureappservice/AzureAppServiceApplicationTests.java
-rw-r--r--  0 0      0        1248  2  2 15:39 AzureAppService/pom.xml
-rwxr-xr-x  0 0      0       11290  2  2 15:39 AzureAppService/mvnw
-rw-r--r--  0 0      0        7592  2  2 15:39 AzureAppService/mvnw.cmd
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/.mvn/
drwxr-xr-x  0 0      0           0  2  2 15:39 AzureAppService/.mvn/wrapper/
-rw-r--r--  0 0      0         233  2  2 15:39 AzureAppService/.mvn/wrapper/maven-wrapper.properties
-rw-r--r--  0 0      0       62547  2  2 15:39 AzureAppService/.mvn/wrapper/maven-wrapper.jar

自動生成されたpom.xmlは以下の通り。前回までにほとんど理解したので説明なし。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="<http://maven.apache.org/POM/4.0.0>" xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>"
	xsi:schemaLocation="<http://maven.apache.org/POM/4.0.0> <https://maven.apache.org/xsd/maven-4.0.0.xsd>">
	<modelVersion>4.0.0</modelVersion>

	<!-- Spring Boot プロジェクトテンプレートの継承 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.2.2</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<groupId>com.example</groupId>
	<artifactId>AzureAppService</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>AzureAppService</name>
	<description>Demo project for Spring Boot</description>

	<!-- 想定java version -->
	<properties>
		<java.version>21</java.version>
	</properties>

	<!-- web関連とtest関連のライブラリを利用 -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<!-- mavenプロジェクトのビルドプラグイン -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

このpom.xmlで新しいのはjava versionを指定するプロパティと、test関連ライブラリ「spring-boot-starter-test」への依存関係定義。今回のスコープはAzure App Serviceへのデプロイなので、test関連は無視。

プログラムの作成

いつものHello World REST。こちらも前回までにほとんど理解したので説明なし。

package com.example.azureappservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class AzureAppServiceApplication {

	@GetMapping("/")
	String home() {
		return "Hello, World.";
	}
	
	public static void main(String[] args) {
		SpringApplication.run(AzureAppServiceApplication.class, args);
	}
}

ローカルPCからの動作確認

いつも通り「mvn spring-boot:run」でローカル実行。

% mvn spring-boot:run
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:AzureAppService >---------------------
[INFO] Building AzureAppService 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot:3.2.2:run (default-cli) > test-compile @ AzureAppService >>>
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ AzureAppService ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ AzureAppService ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ AzureAppService ---
[INFO] skip non existing resourceDirectory /Users/sato/proj/learn/java/SpringTips/AzureAppService/src/test/resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ AzureAppService ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< spring-boot:3.2.2:run (default-cli) < test-compile @ AzureAppService <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot:3.2.2:run (default-cli) @ AzureAppService ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.2)

2024-02-02T15:49:16.165+09:00  INFO 2703 --- [           main] c.e.a.AzureAppServiceApplication         : Starting AzureAppServiceApplication using Java 21.0.1 with PID 2703 (/Users/sato/proj/learn/java/SpringTips/AzureAppService/target/classes started by sato in /Users/sato/proj/learn/java/SpringTips/AzureAppService)
2024-02-02T15:49:16.166+09:00  INFO 2703 --- [           main] c.e.a.AzureAppServiceApplication         : No active profile set, falling back to 1 default profile: "default"
2024-02-02T15:49:16.785+09:00  INFO 2703 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-02-02T15:49:16.797+09:00  INFO 2703 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-02-02T15:49:16.798+09:00  INFO 2703 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-02-02T15:49:16.836+09:00  INFO 2703 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-02-02T15:49:16.837+09:00  INFO 2703 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 635 ms
2024-02-02T15:49:17.077+09:00  INFO 2703 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2024-02-02T15:49:17.083+09:00  INFO 2703 --- [           main] c.e.a.AzureAppServiceApplication         : Started AzureAppServiceApplication in 1.178 seconds (process running for 1.414)

curlで確認。

% curl --header "Content-Type: application/json" --request GET http://localhost:8080 
Hello, World.

Azureリソースグループの作成

CLIを用いたリソース作成時に毎回同じパラメータを指定するよう求められるため、先に環境変数にパラメータ値を設定しておき、CLIから参照できるようにする。

環境変数の設定

CLIを用いたリソース作成時に、毎回指定する必要がある情報は、リソースを作成するコンテナとなるリソースグループと、リソースを配置するリージョン。

この時、作成するリソースのリージョン名を「az account list-locations」で確認しておく。多くの情報が表示される場合、「—output table」を指定すると出力結果がテーブル形式になるため読みやすい。

今回は東日本リージョンにリソースを作成したいので「japaneast」を指定する。

% az account list-locations --output table
DisplayName               Name                 RegionalDisplayName
------------------------  -------------------  -------------------------------------
East US                   eastus               (US) East US
East US 2                 eastus2              (US) East US 2
South Central US          southcentralus       (US) South Central US
West US 2                 westus2              (US) West US 2
West US 3                 westus3              (US) West US 3
Australia East            australiaeast        (Asia Pacific) Australia East
Southeast Asia            southeastasia        (Asia Pacific) Southeast Asia
North Europe              northeurope          (Europe) North Europe
Sweden Central            swedencentral        (Europe) Sweden Central
UK South                  uksouth              (Europe) UK South
West Europe               westeurope           (Europe) West Europe
Central US                centralus            (US) Central US
South Africa North        southafricanorth     (Africa) South Africa North
Central India             centralindia         (Asia Pacific) Central India
East Asia                 eastasia             (Asia Pacific) East Asia
Japan East                japaneast            (Asia Pacific) Japan East
Korea Central             koreacentral         (Asia Pacific) Korea Central
Canada Central            canadacentral        (Canada) Canada Central
France Central            francecentral        (Europe) France Central
Germany West Central      germanywestcentral   (Europe) Germany West Central
Italy North               italynorth           (Europe) Italy North
Norway East               norwayeast           (Europe) Norway East
Poland Central            polandcentral        (Europe) Poland Central
Switzerland North         switzerlandnorth     (Europe) Switzerland North
UAE North                 uaenorth             (Middle East) UAE North
Brazil South              brazilsouth          (South America) Brazil South
Central US EUAP           centraluseuap        (US) Central US EUAP
Israel Central            israelcentral        (Middle East) Israel Central
Qatar Central             qatarcentral         (Middle East) Qatar Central
Central US (Stage)        centralusstage       (US) Central US (Stage)
East US (Stage)           eastusstage          (US) East US (Stage)
East US 2 (Stage)         eastus2stage         (US) East US 2 (Stage)
North Central US (Stage)  northcentralusstage  (US) North Central US (Stage)
South Central US (Stage)  southcentralusstage  (US) South Central US (Stage)
West US (Stage)           westusstage          (US) West US (Stage)
West US 2 (Stage)         westus2stage         (US) West US 2 (Stage)
Asia                      asia                 Asia
Asia Pacific              asiapacific          Asia Pacific
Australia                 australia            Australia
Brazil                    brazil               Brazil
Canada                    canada               Canada
Europe                    europe               Europe
France                    france               France
Germany                   germany              Germany
Global                    global               Global
India                     india                India
Japan                     japan                Japan
Korea                     korea                Korea
Norway                    norway               Norway
Singapore                 singapore            Singapore
South Africa              southafrica          South Africa
Sweden                    sweden               Sweden
Switzerland               switzerland          Switzerland
United Arab Emirates      uae                  United Arab Emirates
United Kingdom            uk                   United Kingdom
United States             unitedstates         United States
United States EUAP        unitedstateseuap     United States EUAP
East Asia (Stage)         eastasiastage        (Asia Pacific) East Asia (Stage)
Southeast Asia (Stage)    southeastasiastage   (Asia Pacific) Southeast Asia (Stage)
Brazil US                 brazilus             (South America) Brazil US
East US STG               eastusstg            (US) East US STG
North Central US          northcentralus       (US) North Central US
West US                   westus               (US) West US
Japan West                japanwest            (Asia Pacific) Japan West
Jio India West            jioindiawest         (Asia Pacific) Jio India West
East US 2 EUAP            eastus2euap          (US) East US 2 EUAP
West Central US           westcentralus        (US) West Central US
South Africa West         southafricawest      (Africa) South Africa West
Australia Central         australiacentral     (Asia Pacific) Australia Central
Australia Central 2       australiacentral2    (Asia Pacific) Australia Central 2
Australia Southeast       australiasoutheast   (Asia Pacific) Australia Southeast
Jio India Central         jioindiacentral      (Asia Pacific) Jio India Central
Korea South               koreasouth           (Asia Pacific) Korea South
South India               southindia           (Asia Pacific) South India
West India                westindia            (Asia Pacific) West India
Canada East               canadaeast           (Canada) Canada East
France South              francesouth          (Europe) France South
Germany North             germanynorth         (Europe) Germany North
Norway West               norwaywest           (Europe) Norway West
Switzerland West          switzerlandwest      (Europe) Switzerland West
UK West                   ukwest               (Europe) UK West
UAE Central               uaecentral           (Middle East) UAE Central
Brazil Southeast          brazilsoutheast      (South America) Brazil Southeast

リソースグループ名は適当な名前で良い。

以下2つの情報は環境変数に設定しておき、いつでも参照できるようにしておく。

% AZ_RESOURCE_GROUP=azure-spring-workshop
% AZ_LOCATION=japaneast

Azure Resource Groupの作成

Bashでは以前にログインした時のセッション情報が残っている場合がある。複数テナントにアカウント持っている人(私もその一人)は、どこにリソースを作成使用しているのか確認するために、現在ログイン中のアカウント情報を確認しておいた方がよい。

ログイン中のAzureアカウント情報は「az account show」で確認できる。

% az account show
{
  "environmentName": "AzureCloud",
  "homeTenantId": "xxx",
  "id": "xxx",
  "isDefault": true,
  "managedByTenants": [],
  "name": "PayAsYouGo",
  "state": "Enabled",
  "tenantId": "xxx",
  "user": {
    "name": "xxx@xxx.onmicrosoft.com",
    "type": "user"
  }
}

まずは「az group create」コマンドでリソースコンテナとなるリソースグループを作成する。

% az group create --name $AZ_RESOURCE_GROUP --location $AZ_LOCATION | jq
{
  "id": "/subscriptions/xxx/resourceGroups/azure-spring-workshop",
  "location": "japaneast",
  "managedBy": null,
  "name": "azure-spring-workshop",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

作成したリソースグループの確認には「az group list」コマンドを用いる。

% az group list --output table
Name                               Location       Status
---------------------------------  -------------  ---------
rg-openai-chat-playground          japaneast      Succeeded
DefaultResourceGroup-EJP           japaneast      Succeeded
NetworkWatcherRG                   japaneast      Succeeded
azure-spring-workshop              japaneast      Succeeded
cloud-shell-storage-southeastasia  southeastasia  Succeeded
DefaultResourceGroup-EUS           eastus         Succeeded


Azure App Serviceへのデプロイ

Azure App Serviceへのデプロイのための設定追加

mavenのazure app serviceプラグインを用いて、以下の2つを実行するためにpom.xmlに設定を追加する。

  • mavenプラグインからAzure App Serviceリソースを作成しWeb Appを作成
  • サンプルプログラムをデプロイしてAzure App Serviceのインスタンスを生成

Azure App Serviceのmavenプラグインは以下にて説明がある。

https://github.com/microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md

Azure App Serviceプラグインのconfigゴールを指定してmavenを実行すると、大量にプラグインモジュールがダウンロードされた後に、pom.xmlに設定を追加する処理が実行される。

% mvn com.microsoft.azure:azure-webapp-maven-plugin:2.9.0:config
[INFO] Scanning for projects...
Downloading from central: <https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-webapp-maven-plugin/2.9.0/azure-webapp-maven-plugin-2.9.0.pom>
Downloaded from central: <https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-webapp-maven-plugin/2.9.0/azure-webapp-maven-plugin-2.9.0.pom> (13 kB at 24 kB/s)
... <プラグインモジュールが大量にダウンロードされる> ...

Create new run configuration (Y/N) [Y]: 
Define value for OS [Linux]:
  1: Windows
* 2: Linux
  3: Docker
Enter your choice: Linux
Invalid value. Enter a value between 1 and 3.

Define value for OS [Linux]:
  1: Windows
* 2: Linux
  3: Docker
Enter your choice: 2
Define value for javaVersion [Java 17]:
  1: Java 8
  2: Java 11
* 3: Java 17
Enter your choice: 3
Define value for pricingTier [P1v2]:
   1: B1
   2: B2
   3: B3
   4: D1
   5: EP1
   6: EP2
   7: EP3
   8: F1
*  9: P1v2
  10: P1v3
  11: P2v2
  12: P2v3
  13: P3v2
  14: P3v3
  15: S1
  16: S2
  17: S3
  18: Y1
Enter your choice: 8
Please confirm webapp properties
AppName : AzureAppService-1707007404722
ResourceGroup : AzureAppService-1707007404722-rg
Region : centralus
PricingTier : F1
OS : Linux
Java Version: Java 17
Web server stack: Java SE
Deploy to slot : false
Confirm (Y/N) [Y]: 
[INFO] Saving configuration to pom.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  16:52 min
[INFO] Finished at: 2024-02-04T09:48:14+09:00
[INFO] ------------------------------------------------------------------------

今回はLinuxベースのFreeプランを選択。

上記を実行した後、pom.xmlにはauzre app serviceのプラグインが登録される。

いくつかの設定値がデフォルトの値で登録されていたので、何か見逃したのかと思ったが、どうやらそういう仕様のようだ。

プロンプトで聞いて欲しかったのに聞かれずにデフォルト値が設定されたのは以下の3つ。

  • resourceGroup
  • appName
  • region
 	<build>
		<plugins>

			<!-- 元々登録してあったspring bootのプラグイン -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>

			<!-- 新たに追加されたAzure App Serviceのプラグイン -->
			<plugin>
				<groupId>com.microsoft.azure</groupId>
			  <artifactId>azure-webapp-maven-plugin</artifactId>
			  <version>2.9.0</version>
			  <configuration>
					<schemaVersion>v2</schemaVersion>
				  <resourceGroup>AzureAppService-1707008778169-rg</resourceGroup>
			    <appName>AzureAppService-1707008778169</appName>
			    <pricingTier>F1</pricingTier>
			    <region>centralus</region>
			    <runtime>
				    <os>Linux</os>
			      <javaVersion>Java 17</javaVersion>
			      <webContainer>Java SE</webContainer>
			    </runtime>
				  <deployment>
				    <resources>
				      <resource>
					      <directory>${project.basedir}/target</directory>
				        <includes>
					        <include>*.jar</include>
			          </includes>
			        </resource>
			      </resources>
			    </deployment>
			  </configuration>
			</plugin>
		</plugins>
	</build>

上記デフォルト値は、再度configゴールを実行するとプロンプトで聞かれる内容が変わり変更できる。なんだこの変な仕様。。

% mvn com.microsoft.azure:azure-webapp-maven-plugin:2.9.0:config
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:AzureAppService >---------------------
[INFO] Building AzureAppService 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- azure-webapp:2.9.0:config (default-cli) @ AzureAppService ---
Please choose which part to config [Application]:
* 1: Application
  2: Runtime
  3: DeploymentSlot
Enter your choice: 
Define value for appName [AzureAppService-1707008778169]: azure-spring-workshop
Define value for resourceGroup [AzureAppService-1707008778169-rg]: azure-spring-workshop
Define value for region [centralus]: japaneast
Define value for pricingTier [F1]:
   1: B1
   2: B2
   3: B3
   4: D1
   5: EP1
   6: EP2
   7: EP3
*  8: F1
   9: P1v2
  10: P1v3
  11: P2v2
  12: P2v3
  13: P3v2
  14: P3v3
  15: S1
  16: S2
  17: S3
  18: Y1
Enter your choice: 8
Please confirm webapp properties
AppName : azure-spring-workshop
ResourceGroup : azure-spring-workshop
Region : japaneast
PricingTier : F1
OS : Linux
Java Version: Java 17
Web server stack: Java SE
Deploy to slot : false
Confirm (Y/N) [Y]: 
[INFO] Saving configuration to pom.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  29.118 s
[INFO] Finished at: 2024-02-04T10:16:49+09:00
[INFO] ------------------------------------------------------------------------

再実行により変更されたpom.xml。

 	<build>
		<plugins>

			<!-- 元々登録してあったspring bootのプラグイン -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>

			<!-- 新たに追加されたAzure App Serviceのプラグイン -->
		  <plugin>
			  <groupId>com.microsoft.azure</groupId>
		    <artifactId>azure-webapp-maven-plugin</artifactId>
		    <version>2.9.0</version>
		    <configuration>
			    <schemaVersion>v2</schemaVersion>
		            
					<!-- 指定したリソースグループ -->
					<resourceGroup>azure-spring-workshop</resourceGroup>
		      <!-- 指定したAppService名 -->
					<appName>azure-spring-workshop</appName>
		      <pricingTier>F1</pricingTier>
		      <!-- 指定したリージョン -->
					<region>japaneast</region>

		      <runtime>
			      <os>Linux</os>
		        <javaVersion>Java 17</javaVersion>
		        <webContainer>Java SE</webContainer>
		      </runtime>
		      <deployment>
			      <resources>
			        <resource>
			          <directory>${project.basedir}/target</directory>
			          <includes>
			            <include>*.jar</include>
		            </includes>
		          </resource>
		        </resources>
		      </deployment>
		    </configuration>
		  </plugin>
		</plugins>
	</build>

Azure App Serviceの作成とサンプルプログラムのデプロイ

以下のコマンドを実行してデプロイを実行。

% mvn package com.microsoft.azure:azure-webapp-maven-plugin:2.9.0:deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:AzureAppService >---------------------
[INFO] Building AzureAppService 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ AzureAppService ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ AzureAppService ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ AzureAppService ---
[INFO] skip non existing resourceDirectory /Users/sato/proj/learn/java/SpringTips/AzureAppService/src/test/resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ AzureAppService ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- surefire:3.1.2:test (default-test) @ AzureAppService ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.azureappservice.AzureAppServiceApplicationTests
10:48:54.942 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.azureappservice.AzureAppServiceApplicationTests]: AzureAppServiceApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
10:48:55.055 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.azureappservice.AzureAppServiceApplication for test class com.example.azureappservice.AzureAppServiceApplicationTests

  .   ____          _            __ _ _
 /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.2)

2024-02-04T10:48:55.421+09:00  INFO 4618 --- [           main] c.e.a.AzureAppServiceApplicationTests    : Starting AzureAppServiceApplicationTests using Java 21.0.1 with PID 4618 (started by sato in /Users/sato/proj/learn/java/SpringTips/AzureAppService)
2024-02-04T10:48:55.422+09:00  INFO 4618 --- [           main] c.e.a.AzureAppServiceApplicationTests    : No active profile set, falling back to 1 default profile: "default"
2024-02-04T10:48:56.449+09:00  INFO 4618 --- [           main] c.e.a.AzureAppServiceApplicationTests    : Started AzureAppServiceApplicationTests in 1.247 seconds (process running for 2.279)
WARNING: A Java agent has been loaded dynamically (/Users/sato/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.11/byte-buddy-agent-1.14.11.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.515 s -- in com.example.azureappservice.AzureAppServiceApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- jar:3.3.0:jar (default-jar) @ AzureAppService ---
[INFO] 
[INFO] --- spring-boot:3.2.2:repackage (repackage) @ AzureAppService ---
[INFO] Replacing main artifact /Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar.original
[INFO] 
[INFO] --- azure-webapp:2.9.0:deploy (default-cli) @ AzureAppService ---
[INFO] Auth type: AZURE_CLI
[INFO] Default subscription: GBS Azure Sandbox(51cf59b2-3184-4d6c-abb6-6ab69af3415c)
[INFO] Username: IOCC_sato@gbssandbox.onmicrosoft.com
[INFO] Subscription: GBS Azure Sandbox(51cf59b2-3184-4d6c-abb6-6ab69af3415c)
[INFO] Start creating App Service plan (asp-azure-spring-workshop)...
[INFO] Using service version null
[INFO] Using service version null
[INFO] App Service plan (asp-azure-spring-workshop) is successfully created
[INFO] Start creating Web App(azure-spring-workshop)...
[INFO] Web App(azure-spring-workshop) is successfully created
[INFO] Trying to deploy external resources to azure-spring-workshop...
[INFO] Successfully deployed the resources to azure-spring-workshop
[INFO] Trying to deploy artifact to azure-spring-workshop...
[INFO] Deploying (/Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar)[jar]  ...
[INFO] Deployment Status: BuildSuccessful; Successful Instance Count: 0; In-progress Instance Count: 0; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[WARNING] Resource deployed, but the deployment is still in process in Azure
[INFO] Successfully deployed the artifact to <https://azure-spring-workshop.azurewebsites.net>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:45 min
[INFO] Finished at: 2024-02-04T10:53:38+09:00
[INFO] ------------------------------------------------------------------------

Azure側で処理中だがデプロイは完了したようで、一旦デプロイ処理は終了した。

Azure App Service PlanとWeb Appインスタンスが作成されている。App Serviceプランの名前には接頭辞として「asp-」が付与されている。

動作確認(エラー発生)

デプロイ結果を確認するためにURL「https://azure-spring-workshop.azurewebsites.net」にアクセスしてみるとエラーになった。。

% curl --header "Content-Type: application/json" --request GET <https://azure-spring-workshop.azurewebsites.net/>
<div style="display: block; margin: auto;  width: 600px; height: 500px; text-align: center; font-family: 'Courier', cursive, sans-serif;"><h1 style="color: 747474">:( Application Error</h1><p style="color:#666">If you are the application administrator, you can access the <a style="color: grey"href="<https://azure-spring-workshop.scm.azurewebsites.net/detectors>">diagnostic resources</a>.</div>

ログストリームでエラー原因の確認

Web Appのログストリームを確認すると、Exceptionが発生していた。ログストリームはWeb Appのサイドメニュー「監視」カテゴリにある「ログストリーム」で確認できる。(ログを見ると何が実行されているのか色々分かって素敵)

重要な部分だけ抜粋したログが以下で、原因箇所は「Exception in thread “main” java.lang.UnsupportedClassVersionError: com/example/azureappservice/AzureAppServiceApplication has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0」の部分。

2024-02-04T02:06:14.850755481Z    _|_|
2024-02-04T02:06:14.850820881Z  _|    _|  _|_|_|_|  _|    _|  _|  _|_|    _|_|
2024-02-04T02:06:14.850830481Z  _|_|_|_|      _|    _|    _|  _|_|      _|_|_|_|
2024-02-04T02:06:14.850836981Z  _|    _|    _|      _|    _|  _|        _|
2024-02-04T02:06:14.850859481Z  _|    _|  _|_|_|_|    _|_|_|  _|          _|_|_|
2024-02-04T02:06:14.850865581Z
2024-02-04T02:06:14.850871081Z      J A V A   O N   A P P   S E R V I C E
2024-02-04T02:06:14.850876682Z
2024-02-04T02:06:14.850882482Z Documentation: <https://aka.ms/appservice>
2024-02-04T02:06:14.850888182Z
2024-02-04T02:06:14.850894082Z **NOTE**: No files or system changes outside of /home will persist beyond your application's current session. /home is your application's persistent storage and is shared across all the server instances.
2024-02-04T02:06:14.851083283Z
2024-02-04T02:06:14.851099883Z
2024-02-04T02:06:14.851364586Z Updating /etc/ssh/sshd_config to use PORT 2222
2024-02-04T02:06:14.883977853Z Starting ssh service...
2024-02-04T02:06:15.074875220Z ssh-keygen: generating new host keys: DSA
2024-02-04T02:06:15.647616520Z  * Starting OpenBSD Secure Shell server sshd
2024-02-04T02:06:15.714304867Z    ...done.
2024-02-04T02:06:15.769937824Z  * sshd is running
2024-02-04T02:06:15.816965610Z ## Printing build info...
2024-02-04T02:06:15.820861442Z                                            PACKAGE |                             VERSION | COMMIT
2024-02-04T02:06:15.820891542Z        Microsoft.AppService.WebsitesExtensionsJava |                         1.0.0250117 |
2024-02-04T02:06:15.820902442Z                                           0a01496e |                                    |
2024-02-04T02:06:15.820909342Z                                               self |                         1.0.0250556 | e16c7680
2024-02-04T02:06:15.822887458Z ## Done printing build info.
2024-02-04T02:06:15.822993059Z Container info: WEBSITE_INSTANCE_ID = 004249e9fb0eec022da5f5cd88d24abf01465ff1cb61a03116d48c4a0329538b ; WEBSITE_SITE_NAME = azure-spring-workshop
2024-02-04T02:06:15.841019907Z Add public certificates to keystore if exists...
2024-02-04T02:06:15.842432719Z Add private certificates to keystore if exists...
2024-02-04T02:06:15.844745638Z Configuring max heap = 716 MB
2024-02-04T02:06:15.877763009Z STARTUP_FILE=
2024-02-04T02:06:15.877799809Z STARTUP_COMMAND=
2024-02-04T02:06:15.877810209Z No STARTUP_FILE available.
2024-02-04T02:06:15.877817409Z No STARTUP_COMMAND defined.
2024-02-04T02:06:16.014689232Z Picked up JAVA_TOOL_OPTIONS: -Xmx716M -Djava.net.preferIPv4Stack=true
2024-02-04T02:06:18.197001939Z Mangled result from Jar entry point parser is: __COM_MICROSOFT_AZURE_APPSERVICE_JARENTRYPOINT_PREFIX__org.springframework.boot.loader.launch.JarLauncher__COM_MICROSOFT_AZURE_APPSERVICE_JARENTRYPOINT_SUFFIX__
2024-02-04T02:06:18.300758391Z Extracted jar entry point. Class name is: 'org.springframework.boot.loader.launch.JarLauncher'
2024-02-04T02:06:18.349664392Z Defaulting to UTF-8
2024-02-04T02:06:18.350231197Z Running command: java -cp /home/site/wwwroot/app.jar:/usr/local/appservice/lib/azure.appservice.jar: -Djava.util.logging.config.file=/usr/local/appservice/logging.properties -Dfile.encoding=UTF-8  -Dserver.port=80 -XX:ErrorFile=/home/LogFiles/java_error_azure-spring-workshop_10-30-0-54_%p.log -XX:+CrashOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/LogFiles/java_memdump_azure-spring-workshop_10-30-0-54.log -Duser.dir=/home/site/wwwroot org.springframework.boot.loader.launch.JarLauncher
2024-02-04T02:06:18.352509715Z Launched child process with pid: 87
2024-02-04T02:06:18.353103020Z Waiting for main process to exit. GLOBAL_PID_MAIN=87
2024-02-04T02:06:18.353127720Z Waiting for GLOBAL_PID_MAIN == 87
2024-02-04T02:06:18.381338852Z Picked up JAVA_TOOL_OPTIONS: -Xmx716M -Djava.net.preferIPv4Stack=true
2024-02-04T02:06:19.131870609Z Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/azureappservice/AzureAppServiceApplication has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
2024-02-04T02:06:19.138272862Z 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
2024-02-04T02:06:19.138427863Z 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
2024-02-04T02:06:19.139173369Z 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
2024-02-04T02:06:19.139812375Z 	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
2024-02-04T02:06:19.139834475Z 	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
2024-02-04T02:06:19.139844475Z 	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
2024-02-04T02:06:19.139852575Z 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
2024-02-04T02:06:19.140320579Z 	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
2024-02-04T02:06:19.140538981Z 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
2024-02-04T02:06:19.140859683Z 	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104)
2024-02-04T02:06:19.141152386Z 	at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
2024-02-04T02:06:19.141308187Z 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
2024-02-04T02:06:19.145602322Z 	at java.base/java.lang.Class.forName0(Native Method)
2024-02-04T02:06:19.145637622Z 	at java.base/java.lang.Class.forName(Class.java:467)
2024-02-04T02:06:19.145650022Z 	at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:88)
2024-02-04T02:06:19.145676223Z 	at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
2024-02-04T02:06:19.145685723Z 	at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
2024-02-04T02:06:19.189583783Z Wait for pid == 87 either returned successfully or was interrupted due to a signal 87
2024-02-04T02:06:19.191009095Z Done waiting for main process. GLOBAL_PID_MAIN=87.
2024-02-04T02:06:19.191050895Z Exiting entry script!
2024-02-04T02:06:13.086Z INFO  - 17-java17_20231113 Pulling from azure-app-service/java
2024-02-04T02:06:13.109Z INFO  -  Digest: sha256:dbad22ba1100bb21199bdb0373ea04afb9d25a7a5767521d2a230daf4dee0c0f
2024-02-04T02:06:13.112Z INFO  -  Status: Image is up to date for 10.1.0.5:13209/azure-app-service/java:17-java17_20231113
2024-02-04T02:06:13.144Z INFO  - Pull Image successful, Time taken: 0 Seconds
2024-02-04T02:06:13.813Z INFO  - Starting container for site
2024-02-04T02:06:13.814Z INFO  - docker run -d --expose=80 --name azure-spring-workshop_0_f4501acc -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITE_SITE_NAME=azure-spring-workshop -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=azure-spring-workshop.azurewebsites.net -e WEBSITE_INSTANCE_ID=004249e9fb0eec022da5f5cd88d24abf01465ff1cb61a03116d48c4a0329538b mcr.microsoft.com/azure-app-service/java:17-java17_20231113
2024-02-04T02:06:13.815Z INFO  - Logging is not enabled for this container.Please use <https://aka.ms/linux-diagnostics> to enable logging to see container logs here.
2024-02-04T02:06:16.194Z INFO  - Initiating warmup request to container azure-spring-workshop_0_f4501acc for site azure-spring-workshop
2024-02-04T02:06:31.542Z ERROR - Container azure-spring-workshop_0_f4501acc for site azure-spring-workshop has exited, failing site start
2024-02-04T02:06:31.560Z ERROR - Container azure-spring-workshop_0_f4501acc didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.
2024-02-04T02:06:31.581Z INFO  - Stopping site azure-spring-workshop because it failed during startup.

単純に、ビルド時のJavaバージョンとランタイムのJavaバージョンの不一致で、classファイルのロードに失敗しているという事だった。

pom.xmlのターゲットjavaバージョンをランタイムバージョンに合わせる。

<project ...>
	...

  <properties>

		<!-- ここをruntime/javaVersionに合わせた -->
		<java.version>17</java.version>

	</properties>
	...

	<build>
		<plugins>
			<plugin>
				<groupId>com.microsoft.azure</groupId>
				...

				<configuration>
					...

					<runtime>
						<os>Linux</os>
		        <javaVersion>Java 17</javaVersion>
		        <webContainer>Java SE</webContainer>
		      </runtime>

再デプロイと動作確認(成功)

再デプロイ時の注意事項は、今回pom.xmlファイルだけ変更しJavaソースコードは変更していないため、そのままdeployコマンドを実行すると再コンパイルされずに前のclassファイルがデプロイされる。

このため、最初のゴールとしてcleanも含める事で再コンパイルを実行してからdeployする。

% mvn clean package com.microsoft.azure:azure-webapp-maven-plugin:2.9.0:deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:AzureAppService >---------------------
[INFO] Building AzureAppService 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.3.2:clean (default-clean) @ AzureAppService ---
[INFO] Deleting /Users/sato/proj/learn/java/SpringTips/AzureAppService/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ AzureAppService ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ AzureAppService ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 17] to target/classes
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ AzureAppService ---
[INFO] skip non existing resourceDirectory /Users/sato/proj/learn/java/SpringTips/AzureAppService/src/test/resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ AzureAppService ---
[INFO] Changes detected - recompiling the module! :dependency
[INFO] Compiling 1 source file with javac [debug release 17] to target/test-classes
[INFO] 
[INFO] --- surefire:3.1.2:test (default-test) @ AzureAppService ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.azureappservice.AzureAppServiceApplicationTests
11:21:48.404 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.azureappservice.AzureAppServiceApplicationTests]: AzureAppServiceApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
11:21:48.501 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.azureappservice.AzureAppServiceApplication for test class com.example.azureappservice.AzureAppServiceApplicationTests

  .   ____          _            __ _ _
 /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\
( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\
 \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.2)

2024-02-04T11:21:48.836+09:00  INFO 5458 --- [           main] c.e.a.AzureAppServiceApplicationTests    : Starting AzureAppServiceApplicationTests using Java 21.0.1 with PID 5458 (started by sato in /Users/sato/proj/learn/java/SpringTips/AzureAppService)
2024-02-04T11:21:48.837+09:00  INFO 5458 --- [           main] c.e.a.AzureAppServiceApplicationTests    : No active profile set, falling back to 1 default profile: "default"
2024-02-04T11:21:49.764+09:00  INFO 5458 --- [           main] c.e.a.AzureAppServiceApplicationTests    : Started AzureAppServiceApplicationTests in 1.132 seconds (process running for 1.984)
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: A Java agent has been loaded dynamically (/Users/sato/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.11/byte-buddy-agent-1.14.11.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.408 s -- in com.example.azureappservice.AzureAppServiceApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- jar:3.3.0:jar (default-jar) @ AzureAppService ---
[INFO] Building jar: /Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot:3.2.2:repackage (repackage) @ AzureAppService ---
[INFO] Replacing main artifact /Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar.original
[INFO] 
[INFO] --- azure-webapp:2.9.0:deploy (default-cli) @ AzureAppService ---
[INFO] Auth type: AZURE_CLI
[INFO] Default subscription: GBS Azure Sandbox(51cf59b2-3184-4d6c-abb6-6ab69af3415c)
[INFO] Username: IOCC_sato@gbssandbox.onmicrosoft.com
[INFO] Subscription: GBS Azure Sandbox(51cf59b2-3184-4d6c-abb6-6ab69af3415c)
[INFO] Trying to deploy external resources to azure-spring-workshop...
[INFO] Successfully deployed the resources to azure-spring-workshop
[INFO] Trying to deploy artifact to azure-spring-workshop...
[INFO] Deploying (/Users/sato/proj/learn/java/SpringTips/AzureAppService/target/AzureAppService-0.0.1-SNAPSHOT.jar)[jar]  ...
[INFO] Using service version null
[INFO] Using service version null
[INFO] Deployment Status: BuildSuccessful; Successful Instance Count: 0; In-progress Instance Count: 0; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[INFO] Deployment Status: RuntimeStarting; Successful Instance Count: 0; In-progress Instance Count: 1; Failed Instance Count: 0
[WARNING] Resource deployed, but the deployment is still in process in Azure
[INFO] Successfully deployed the artifact to <https://azure-spring-workshop.azurewebsites.net>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:09 min
[INFO] Finished at: 2024-02-04T11:25:55+09:00
[INFO] ------------------------------------------------------------------------

今度は正常に実行された。

% curl --header "Content-Type: application/json" --request GET https://azure-spring-workshop.azurewebsites.net
Hello, World.

コメント

タイトルとURLをコピーしました