【发布时间】:2022-01-16 18:24:20
【问题描述】:
我在使用 spring-boot-maven-plugin 启动应用程序时尝试使用 @ConditionalOnProperty。
如果我使用 eclipse 启动项目,我只需将“-Dexample=true”添加到 vm Arguments。
@ConditionalOnProperty( name = "example", havingValue = "true", matchIfMissing = false )
我尝试用 spring-boot-maven-plugin 做同样的事情
我试过了
<jvmArguments>-Dexample=true</jvmArguments>
<jvmArguments>-Dspring-boot.run.arguments="--example=true"</jvmArguments>
<arguments>
<argument>-Dexample=true</argument>
<argument>-Dspring-boot.run.arguments="--example=true"</argument>
</arguments>
但这些都不起作用。
如果我添加个人资料
<jvmArguments>-Dspring.profiles.active=exampleProfile</jvmArguments>
其中包含参数example:true 它可以工作。 `
编辑:
确切的论点是
<arguments>
<arguement>openapi.offline=true</arguement>
</arguments>
但仍然找不到该属性
- @ConditionalOnProperty (openapi.offline=true) did not find property 'offline'
我的条件:
@ConditionalOnProperty( prefix = "openapi", name = "offline", havingValue = "true", matchIfMissing = false )
解决方案: 我有多个
<jvmArguments> -example1 </jvmArguments>
<jvmArguments> -example2 </jvmArguments>
但它们相互覆盖。所以我不得不把它们都放在一个 jvmarguemnts 字段中
<jvmArguments> -example1 -example2 </jvmArguments>
【问题讨论】:
标签: spring-boot properties pom.xml spring-boot-maven-plugin