我正在尝试将我的 springboot 项目部署到 Azure 应用服务中。 我创建了一个应用服务并通过 FTP 上传了两个文件:test.war 和 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 "%HOME%\site\wwwroot\test.war"">
</httpPlatform>
</system.webServer>
</configuration>
我将 war 文件上传到 site/wwwroot 并将 web.config 文件也放置在那里。
我的问题是:如何执行war文件?当我自动完成部署时应该发生这种情况吗?因为现在我得到的只是服务不可用,Http 错误 503。
谢谢
最佳答案
@ItaiSoudry,根据您web.config
的内容文件中,似乎您想使用嵌入式 servlet 容器(如嵌入式 tomcat 或 jetty)来启动 spring boot web 应用程序。
假设您使用的IDE是Eclipse,您需要将您的Spring Boot项目导出为可运行的jar文件,而不是war文件,请参见下图。
注意:Launch configuration
应选择main函数包含的ClassSpringApplication.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 "%HOME%\site\wwwroot\test.jar"">
</httpPlatform>
</system.webServer>
</configuration>
如果要部署war文件,需要配置ApplicationSettings
在 Azure 门户上创建您的应用服务,然后将 war 文件上传到路径 wwwroot/webapps
.
作为引用,请参阅以下文档。
Springboot
文章中的小节https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples- Create a Java web app in Azure App Service
希望有帮助。
关于java - 将 Springboot 部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39103878/