请使用 spring 和 azure 社区提供的以下步骤在 azure 上部署 spring boot 应用程序:
1) 进入你有 pom 文件的应用文件夹并运行
确保以下插件应该在 pom 文件中
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<!-- tag::tests[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- end::tests[] -->
</dependencies>
<properties>
<java.version>1.8</java.version>
<maven.build.timestamp.format>yyyyMMddHHmmssSSS</maven.build.timestamp.format>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>0.1.5</version>
<configuration>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<resourceGroup>maven-plugin</resourceGroup>
<appName>maven-web-app-${maven.build.timestamp}</appName>
<region>westus</region>
<javaVersion>1.8</javaVersion>
<deploymentType>ftp</deploymentType>
<stopAppDuringDeployment>true</stopAppDuringDeployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<targetPath>/</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}</directory>
<targetPath>/</targetPath>
<includes>
<include>web.config</include>
</includes>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
注意:确保您已在 azure 上创建了同名的网络应用程序
maven-web-app-${maven.build.timestamp}
现在在根目录下创建名为“web.config”的文件,并将你的 jar 添加到 web.comfig 中
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\azure-rest-example-app-0.1.0.jar"">
</httpPlatform>
</system.webServer>
</configuration>
现在打开 azure CLI 并运行以下命令
- mvn 清洁包
- mvn spring-boot:run
确保应用在本地运行良好。
如果您有多个与您的 id 关联的帐户,现在使用以下命令
现在您需要创建“Microsoft Azure 中的服务主体”
1) 打开一个终端窗口。
2) 通过键入 az login 使用 Azure CLI 登录您的 Azure 帐户
3) 通过键入 az ad sp create-for-rbac --name "vaquarkhan" --password "yourpassword" 创建 Azure 服务主体(vaquarkhan 是用户名,yourpassword 是服务主体的密码)。
az ad sp create-for-rbac --name "app-name" --password "password"
注意:如果出现错误需要更改设置---> here
“azure.graphrbac.models.graph_error.GraphErrorException:来宾用户
不允许执行此操作。”
如果成功
Azure 应该打印出类似于以下内容的 JSON 响应:
{
"appId": "XXX-XXXX-XXX-XXX-XXXX",
"displayName": "vaquarkhan",
"name": "http://vaquarkhan",
"password": "yourpassword",
"tenant": "YYY-YYYY-YYY-YYY-YYYY"
}
配置 Maven 以使用您的 Azure 服务主体
1) 在文本编辑器中打开 Maven settings.xml 文件(通常位于 /etc/maven/settings.xml 或 $HOME/.m2/settings.xml)。
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>azure-auth</id>
<configuration>
<client>ur key</client>
<tenant>ur tenant</tenant>
<key>YOUR PASSWORD</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
<proxies/>
<profiles>
<profile>
<id>hwx</id>
<repositories>
<repository>
<id>hwx</id>
<name>hwx</name>
<url>http://nexus-private.hortonworks.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</profile>
</profiles>
<mirrors>
<mirror>
<id>public</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus-private.hortonworks.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<activeProfiles/>
</settings>
2) 将本教程上一部分中的 Azure 服务主体设置添加到 settings.xml 文件中的集合中,如下所示:
<servers>
<server>
<id>azure-auth</id>
<configuration>
<client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client>
<tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant>
<key>pppppppp</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
3) 保存并关闭 settings.xml 文件。
构建您的应用并将其部署到 Azure
1) 运行以下命令
- mvn azure-webapp:deploy
部署 Web 应用后,访问 Azure 门户进行管理
它。它将列在应用服务中。
单击应用程序。从那里,面向公众的 URL
您的网络应用将列在概览部分中
确定您的 Web 应用程序的 URL 您可以单击此链接以
访问 Spring Boot 应用并与之交互。
Azure maven 插件文档
注意:网站名称必须是全球唯一的,并且其生成
使用应用名称,确保名称应该是唯一的。