以最快速度启动 Azure Spring Apps (ASA)
以最快速度启动Azure Spring Apps(ASA)。

为了某种目标而行动或达到某种结果。
在Windows 11上使用Linux进行云开发。
您可以在这里查看文章的列表。
实现
使用Ubuntu本地环境,借助Shell脚本将Spring Boot JAR文件格式的应用程序部署到Azure Spring Apps上。
首先
大家喜欢使用 Azure 吗?这次我们想尝试一下不同的方法,尽快启动 Azure Spring Apps。
相关文章
让我们与其他Azure PaaS服务进行比较!
开发环境
- Windows 11 Home 22H2 を使用しています。
> wsl –version
WSL 版本:1.0.3.0
内核版本:5.15.79.1
WSLg 版本:1.0.47Ubuntu ※ 您可以在相关文章中查看安装方法
$ lsb_release -a
无可用的 LSB 模块。
发行商 ID:Ubuntu
描述:Ubuntu 22.04.1 LTS
发行版本:22.04
Java JDK ※ 您可以在相关文章中查看安装方法
$ java -version
openjdk version “11.0.18” 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)
Maven ※ 您可以在相关文章中查看安装方法
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Azure CLI ※ 您可以在相关文章中查看安装方法
$ az –version
azure-cli 2.45.0
core 2.45.0
telemetry 1.0.8
创建Spring Boot应用程序
您可以在这篇相关文章中确认步骤。
进入项目文件夹
我們切換至專案資料夾。
※ 假設 ~/tmp/hello-spring-boot 為專案資料夾。
$ cd ~/tmp/hello-spring-boot
启动Spring Apps
我会编写一个 Shell 脚本。
$ vim create_spring_apps.sh
依据情况,请修改以下三个参数。
编号 参数 内容
1 resource_group_name=rg-hello rg-hello 资源组的名称。
2 spring_service_name=aps-hello aps-hello Spring Apps 服务的名称。
3 spring_app_name=sap-hello-spring-boot sap-hello-spring-boot Spring Apps 应用的名称。
#!/bin/sh
# set variables.
location_name=japaneast
resource_group_name=rg-hello
spring_service_name=aps-hello
spring_app_name=sap-hello-spring-boot
# create a resource group
az group create \
--name $resource_group_name \
--location $location_name
# create a spring service.
az spring create \
--resource-group $resource_group_name \
--name $spring_service_name \
--location $location_name \
--sku Basic
# create a spring app.
az spring app create \
--resource-group $resource_group_name \
--service $spring_service_name \
--name $spring_app_name \
--runtime-version Java_11 \
--assign-endpoint true
# deploy a spring app.
az spring app deploy \
--resource-group $resource_group_name \
--service $spring_service_name \
--name $spring_app_name \
--artifact-path target/app.jar
# get a spring service id.
spring_service_id=$(az spring list \
--query "[0].id" \
-o tsv)
# get a signed in user id.
signed_in_user_id=$(az ad signed-in-user show \
--query id \
-o tsv)
# create a spring app connect role.
az role assignment create \
--role 'Azure Spring Apps Connect Role' \
--scope $spring_service_id \
--assignee $signed_in_user_id
# get a spring app data.
curl https://$spring_service_name-$spring_app_name.azuremicroservices.io/api/data -w '\n'
给予执行权限。
$ chmod +x create_spring_apps.sh
登入 Azure。
$ az login
您可以在这篇相关文章中查看步骤。
执行Shell脚本。
$ ./create_spring_apps.sh
当部署完成后,会显示以下内容。
{"message":"Hello World!"}
打开 Azure 门户并查看

删除Spring Apps
我要创建一个Shell脚本。
$ vim delete_resource_group.sh
请将以下参数与上面创建的参数进行匹配。
| No | 行 | 参数 | 内容 |
|—-|—-|——|——|
| 1 | resource_group_name=rg-hello | rg-hello | 资源组的名称。|
文件的内容 de
#!/bin/sh
# set variables.
resource_group_name=rg-hello
# delete resource group
az group delete \
--name $resource_group_name \
--yes
添加执行权限。
$ chmod +x delete_resource_group.sh
执行shell脚本。
$ ./delete_resource_group.sh
在删除过程中,将显示如下。
/ Running ..
总结
在Azure Spring Apps环境中,可以轻松启动以JAR文件格式的Spring Boot Web应用程序。
请问您对于在WSL Ubuntu上能够便捷地搭建Azure云应用开发环境有何看法?请务必试一试。我们将继续介绍Azure的开发环境等内容,请务必期待。
推荐内容