繁体   English   中英

将Springboot部署到Azure App Service

[英]Deploying Springboot to Azure App Service

我正在尝试将springboot项目部署到Azure应用服务中。 我创建了一个应用程序服务,并通过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文件也放置在那里。

我的问题是:如何执行战争文件? 完成自动部署后应该发生这种情况吗? 因为现在我得到的只是服务不可用,HTTP错误503。

谢谢

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

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

在此处输入图片说明

在此处输入图片说明

注意:应该选择Launch configuration为Class,其主要功能包含SpringApplication.run

同时,您需要通过web.config文件中的参数--server.port=%HTTP_PLATFORM_PORT%将配置为%HTTP_PLATFORM_PORT%的Azure应用服务所支持的侦听端口,或将ServerProperties类的端口设置为System.getenv("HTTP_PLATFORM_PORT")

这是带有--server.port=%HTTP_PLATFORM_PORT% 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.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

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

在此处输入图片说明

作为参考,请参考以下文档。

  1. https://azure.microsoft.com/zh-cn/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples文章中的Springboot小节
  2. 在Azure应用服务中创建Java Web应用

希望能帮助到你。

暂无
暂无

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

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