【问题标题】:spring-boot-maven-plugin @ConditionalOnPropertyspring-boot-maven-plugin @ConditionalOnProperty
【发布时间】: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


    【解决方案1】:

    你不需要-D 试试这个:

        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>....</version>
        <configuration>
          <arguments>
            <argument>--openapi.offline=true</argument>
          </arguments>
        </configuration>
    

    【讨论】:

    • 感谢您的回复,确切的争论是 openapi.offline=true ` openapi.offline=true` 但仍然找不到该属性@ 987654323@`@ConditionalOnProperty(前缀=“openapi”,名称=“离线”,有值=“真”,matchIfMissing =假)`
    • 好的。您可以尝试在属性之前添加--。 (编辑答案)
    • 同样的错误。但是谢谢
    • 奇怪。如果您将 openapi.offline=true 添加到您的属性文件中,它会跳过 bean 创建吗? (只是为了测试,你可以试试吗)?
    • 好的,我发现了。我的 Pom 中有多个 行,如果我将所有内容都放在一个 jvmArgument 中,则可以相互覆盖。我将为问题添加一个解决方案。
    猜你喜欢
    • 1970-01-01
    • 2018-05-06
    • 2017-06-20
    • 2020-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多