简体   繁体   中英

Spring Boot App on Azure with Command Line Arguments

Is it possible to pass command line arguments to a Spring boot app on Azure via the web.config file? Our app is up and running but we need to set the:

--spring.profiles.active=local

at startup.

<?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>

I got a response from Microsoft and they had two ways:

  1. Add "environmentVariables" block to the xml above:

Add "environmentVariables" block to the xml above:

<?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. Add this in the App settings.

[ 在此处输入图片说明

3, Actually, neither of those worked for us. We had to do this:

<?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>

AND #2 above.

Configuration-> Application Settings, I've simply added:

在此处输入图片说明

After that, Springboot could load: application-prod.properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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