首页 文章

将Springboot部署到Azure App Service

提问于
浏览
1

我正在尝试将springboot项目部署到Azure App Service中 . 我创建了一个App Service并通过FTP上传了两个文件:test.war和web.config,如他们的教程中所述 .

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\test.war&quot;">
    </httpPlatform> 
  </system.webServer>
</configuration>

我正在将war文件上传到site / wwwroot并将web.config文件放在那里 .

我的问题是:我如何执行war文件?是否应该在我自动完成部署时发生?因为现在我得到的是Service Unavailable,Http Error 503 .

谢谢

1 回答

  • 2

    @ItaiSoudry,根据 web.config 文件的内容,您似乎希望使用嵌入式servcat容器(如嵌入式tomcat或jetty)来启动spring boot Web应用程序 .

    假设您使用的IDE是Eclipse,您需要将Spring启动项目导出为可运行的jar文件,而不是war文件,请参见下图 .

    enter image description here

    enter image description here

    注意: Launch configuration 应该选择主函数包含 SpringApplication.run 的类 .

    同时,您需要通过 web.config 文件中的参数 --server.port=%HTTP_PLATFORM_PORT% 配置支持Azure应用程序的 %HTTP_PLATFORM_PORT% 监听端口,或者使用值 System.getenv("HTTP_PLATFORM_PORT") 设置类ServerProperties的端口 .

    以下是 web.config--server.port=%HTTP_PLATFORM_PORT% 的示例 .

    <?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\test.jar&quot;">
        </httpPlatform>
      </system.webServer>
    </configuration>
    

    如果要部署war文件,则需要在Azure门户上配置应用程序服务的 ApplicationSettings ,然后将war文件上载到路径 wwwroot/webapps 中 .

    enter image description here

    作为参考,请参阅以下文件 .

    希望能帮助到你 .

相关问题