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

标签 java spring azure spring-boot azure-webjobs

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

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

最佳答案

我收到了 Microsoft 的回复,他们有两种方法:

  1. 将“environmentVariables” block 添加到上面的 xml 中:

将“environmentVariables” block 添加到上面的 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>
  • 将其添加到应用设置中。
  • [enter image description here

    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。

    关于java - Azure 上带有命令行参数的 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49391267/

    相关文章:

    java - JSF/ICEfaces 动态层次结构树示例

    java - LibreOffice UNO Java API : how to open a document, 执行宏并关闭它?

    java - Spring Cache @Cacheable - 从同一个bean的另一个方法调用时不起作用

    azure - Cosmos 文档 - 存储过程 : Save & Execute button is Grey out

    c# - java 和 c# 中右移运算符的不同结果

    java - 列表列表到 MapList Java 8 Lambda 的映射列表

    Spring 5 响应式(Reactive)异常处理

    spring - 将 SSE-Emitter 对象保存到 MongoDB/Redis 中,从数据库中获取它并通过它发送事件

    javascript - 如何清除 MSAL SPA 中的缓存 token ?

    azure - 如何使 terraform 资源中的字段成为可选字段?