Azure 上带有命令行参数的 Spring Boot 应用程序

mar*_*rea 2 java spring azure spring-boot azure-webjobs

是否可以通过 web.config 文件将命令行参数传递给 Azure 上的 Spring boot 应用程序?我们的应用程序已启动并正在运行,但我们需要设置:

--spring.profiles.active=local
Run Code Online (Sandbox Code Playgroud)

在启动时。

<?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>
Run Code Online (Sandbox Code Playgroud)

mar*_*rea 5

我得到了微软的回复,他们有两种方式:

  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>
Run Code Online (Sandbox Code Playgroud)
  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>
Run Code Online (Sandbox Code Playgroud)

和上面#2。