是否可以通过 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 "%HOME%\site\wwwroot\myjar-0.0.1.jar"">
</httpPlatform>
</system.webServer>
</configuration>
最佳答案
我收到了 Microsoft 的回复,他们有两种方法:
- 将“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 "%HOME%\site\wwwroot\AssetCommander-0.0.1.jar"">
<environmentVariables>
<environmentVariable name="JAVA_OPTS" value="-Dspring.profiles.active=dev" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
- 将其添加到应用设置中。
[
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 "%HOME%\site\wwwroot\AssetCommander-0.0.1.jar"">
</httpPlatform>
</system.webServer>
</configuration>
以及上面的#2。
关于java - Azure 上带有命令行参数的 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49391267/