繁体   English   中英

在Azure App Service上部署Spring Boot jar

[英]Deploy Spring Boot jar on Azure App Service

我无法让Spring Boot API在Azure应用服务上运行。 我遵循了https://docs.microsoft.com/zh-cn/java/azure/spring-framework/deploy-spring-boot-java-web-app-on-azure上的Microsoft指南,但是没有运气远。

该应用程序确实启动了(我可以在日志文件中看到该应用程序已启动),但是对应用程序服务URL的http请求始终以超时结束。

我已经读过,Azure应用程序服务只能选择运行在端口80或8080上的嵌入式tomcat服务器,但也没有运气。

该应用程序部署在www根目录中,同时也部署了适当的web.config。

我尝试在有和没有应用程序服务器(Tomcat和Jetty,因为服务器已嵌入应用程序中而不需要)中运行App Service,但是两种方法都失败了。

我是否缺少其他配置部分? 还是这可能与我在天青上使用的计划类型有关? 也许资源有问题?

有指针吗?

谢谢,

伯特

请使用spring and azure社区给出的以下步骤在azure上部署spring boot应用程序:

1)进入您拥有pom文件的app文件夹并运行

确保以下插件应该在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>

注意:请确保您已经在天蓝色上创建了与以下名称相同的网络应用
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 &quot;%HOME%\site\wwwroot\azure-rest-example-app-0.1.0.jar&quot;">
        </httpPlatform>
    </system.webServer>
</configuration>

在此处输入图片说明

现在打开azure CLI并运行以下命令 在此处输入图片说明

  • mvn清洁包装
  • mvn spring-boot:运行

确保应用在本地运行正常。

现在,如果您有多个与ID关联的帐户,请使用以下命令

  • az登录

  • AZ帐户列表

  • AZ帐户集-订阅XXX-XXX-XXX-XXXXXXXXXXXX

现在,您需要创建“ Microsoft Azure中的服务主体”

1)打开一个终端窗口。

2)通过输入az登录名使用Azure CLI登录到您的Azure帐户

3)通过键入az ad sp create-for-rbac --name“ vaquarkhan” --password“ yourpassword”(vaquarkhan是用户名,而yourpassword是服务主体的密码)来创建Azure服务主体。

az ad sp-为rbac创建--name“ app-name” --password“ password”

注意:如果遇到错误,请在此处更改设置--->

“ 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:部署
  • 部署Web应用程序后,请访问Azure门户进行管理。 它将在App Services中列出。

  • 单击该应用程序。 从那里开始,您的网络应用的公开网址将在“概述”部分列出

  • 确定您的Web应用程序的URL您可以单击此链接来访问Spring Boot应用程序并与其进行交互。

在此处输入图片说明 在此处输入图片说明

Azure Maven插件文档

注意:网站名称必须是全局唯一的,并且使用应用名称生成,请确保名称应该唯一。

结合官方教程中的步骤和您的实际情况,我提供以下检查点:

要点1:请使用mvn packagepom.xml文件所在的目录中构建JAR软件包。

在此处输入图片说明 ]

第2点:请确保在web.config中配置的jar包名称与上载的jar包名称相同。

在此处输入图片说明

web.config

<?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 &quot;%HOME%\site\wwwroot\<your project name>&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

第3点:请使用FTP将jar filesweb.config发布到KUDU上的D:\\home\\site\\wwwroot\\目录。

第4点:请确保ApplicationSettings与您的项目匹配,例如jdk versiontomcat version

在此处输入图片说明

如果要部署war文件,则需要在Azure门户上配置应用程序服务的ApplicationSettings,然后将war文件上传到路径D:\\home\\site\\wwwroot\\webapps

另外,您可以检查KUDU上的日志文件: https://<your project name>.scm.azurewebsites.net/DebugConsole.

作为参考,请参考下面的文档和主题。

1. 在Azure App Service中配置Web应用程序

2. 在Azure App Service中创建一个Java Web应用程序

3.将Springboot部署到Azure应用服务

希望对您有帮助。

为了使Springboot应用程序运行,您需要上传JAR文件并添加web.config文件。

要将要运行的内容传达给服务,您需要将web.config文件添加到应用程序服务的site \\ wwwroot文件夹中。 当您已经创建了web.config文件时,请使用Maven添加以下内容并获得动态包含在软件包中的项目/发行版。

<build>
    <resources>
        <resource>
            <directory>${project.basedir}/wwwroot</directory>
            <filtering>true</filtering>
            <targetPath>${basedir}/target</targetPath>
        </resource>
    </resources>
</build> 

现在,将jar文件和web.config放在Azure App Service中。

您只需检查一下是否创建了如下的web.config文件,

<?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 &quot;%HOME%\site\wwwroot\@project.artifactId@-@project.version@.jar&quot;">
        </httpPlatform>
    </system.webServer>
</configuration>

事实证明,我对这是天蓝色资源问题的预感是正确的。 升级资源内存和CPU解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM