将Springboot部署到Azure应用服务

问题描述:

我试图将我的springboot项目部署到Azure应用服务。 我创建了一个App服务,并通过FTP上传两个文件:test.war和web.config,如他们的教程中所述。将Springboot部署到Azure应用服务

的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文件到网站/ wwwroot文件并放置在web.config文件中有作为。

我的问题是:如何执行war文件?它会在我自动完成部署时发生吗?导致现在我得到的是服务不可用,HTTP错误503

感谢

@ItaiSoudry,根据您的web.config文件的内容,似乎要使用嵌入式servlet容器如嵌入式Tomcat或jetty启动Spring Boot Web应用程序。

假设您使用的IDE是Eclipse,您需要将弹簧引导项目导出为可运行jar文件,而不是war文件,请参阅下图。

enter image description here

enter image description here

注:Launch configuration应选择其中主函数包含SpringApplication.run类。

同时,你需要配置监听端口与%HTTP_PLATFORM_PORT%通过参数--server.port=%HTTP_PLATFORM_PORT%支持Azure的应用服务在web.config文件或设置类ServerProperties的端口值System.getenv("HTTP_PLATFORM_PORT")

以下是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

作为参考,请参阅下面的文档。

  1. Springboot款文章https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples
  2. Create a Java web app in Azure App Service

希望它可以帮助英寸