簡體   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