我正在尝试将springboot项目部署到Azure App Service中. 我创建了一个应用服务,并通过FTP上传了两个文件:test.war和web.config,如其教程中所述.
I'm trying to deploy my springboot project into Azure App Service. I created an App Service and uploaded via FTP two files: test.war and web.config as mentioned in their tutorials.
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.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\test.war""> </httpPlatform> </system.webServer> </configuration>我正在将war文件上传到site/wwwroot,并将web.config文件也放置在其中.
I'm uploading the war file into the site/wwwroot and placed the web.config file there as well.
我的问题是:如何执行war文件?完成自动部署后应该发生这种情况吗?原因现在我得到的只是服务不可用,HTTP错误503.
My question is: How do I execute the war file? is it supposed to happen when I finish deploy automatically? cause right now all I get is Service Unavailable, Http Error 503.
谢谢
推荐答案@ItaiSoudry,根据您的web.config文件的内容,您似乎想要使用嵌入式servlet容器(例如嵌入式tomcat或jetty)来启动Spring Boot Web应用程序.
@ItaiSoudry, According to the content of your web.config file, it seems that you want to use the embedded servlet container like embedded tomcat or jetty to start up the spring boot web application.
假设您使用的IDE是Eclipse,则需要将spring boot项目导出为可运行的jar文件,而不是war文件,请参见下图.
Assumption that the IDE you used is Eclipse, you need to export your spring boot project as a runnable jar file, not a war file, please see the figure below.
注意:Launch configuration应该选择为主函数包含SpringApplication.run的Class.
Note: The Launch configuration should be selected the Class which the main function contains SpringApplication.run.
同时,您需要使用%HTTP_PLATFORM_PORT%通过web.config文件中的参数--server.port=%HTTP_PLATFORM_PORT%支持的Azure App服务配置监听端口,或设置类 ServerProperties 的值为System.getenv("HTTP_PLATFORM_PORT").
Meanwhile, you need to configure the listen port with %HTTP_PLATFORM_PORT% the Azure App service supported via the argument --server.port=%HTTP_PLATFORM_PORT% in the web.config file or set the port of the class ServerProperties with the value 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.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\test.jar""> </httpPlatform> </system.webServer> </configuration>如果要部署War文件,则需要在Azure门户上配置应用程序服务的ApplicationSettings,然后将war文件上传到路径wwwroot/webapps.
If you want to deploy a war file, you need to configure the ApplicationSettings of your app service on Azure portal, then upload the war file into the path wwwroot/webapps.
作为参考,请参阅以下文档.
As references, please refer to the documents below.
希望有帮助.
更多推荐
将Springboot部署到Azure App Service
发布评论