簡體   English   中英

帶有命令行參數的 Azure 上的 Spring Boot 應用程序

[英]Spring Boot App on Azure with Command Line Arguments

是否可以通過 web.config 文件將命令行參數傳遞給 Azure 上的 Spring 啟動應用程序? 我們的應用程序已啟動並正在運行,但我們需要設置:

--spring.profiles.active=local

在啟動時。

<?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="ack=t-Djava.net.preferIPv4Strue -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\myjar-0.0.1.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

我收到了微軟的回復,他們有兩種方式:

  1. 將“environmentVariables”塊添加到上面的 xml 中:

將“environmentVariables”塊添加到上面的 xml 中:

<?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\AssetCommander-0.0.1.jar&quot;"> 
       <environmentVariables> 
          <environmentVariable name="JAVA_OPTS" value="-Dspring.profiles.active=dev" /> 
       </environmentVariables> 
    </httpPlatform> 
  </system.webServer> 
</configuration>
  1. 在應用程序設置中添加此項。

[在此處輸入圖片說明

3,實際上,這些都不適合我們。 我們不得不這樣做:

<?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 -Dspring.profiles.active=%spring.profiles.active% -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\AssetCommander-0.0.1.jar&quot;">
            </httpPlatform>
      </system.webServer>
    </configuration>

和上面的#2。

配置-> 應用程序設置,我只是添加了:

在此處輸入圖片說明

之后,Springboot 可以加載:application-prod.properties

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM