【问题标题】:How get negated value inside spring boot application.yml如何在spring boot application.yml中获得否定值
【发布时间】:2020-04-16 22:25:19
【问题描述】:

有没有办法将一个变量的否定值分配给另一个变量,配置application.yml spring boot文件。 类似的东西

org:
 property: true
property2: !${org.property}

我尝试了几种方法,但总是春天抱怨它。 谢谢

【问题讨论】:

    标签: spring-boot yaml


    【解决方案1】:

    在你的配置类中否定它:

    @ConfigurationProperties("org")
    public class AppProperties {
        private boolean property;
    
        // getter setter
    }
    
    @Configuration
    @EnableConfigurationProperties(value = AppProperties.class)
    public class AppConfig {
        private final AppProperties appProperties;
        private boolean property2;
    
        public AppConfig(AppProperties appProperties) {
            this.appProperties = appProperties;
            property2 = !appProperties.getProperty();
        }
    
        // getter setter
    }
    

    【讨论】:

      【解决方案2】:

      您不能直接在 YAML 中执行任何逻辑,因为 YAML 只是一种可与 XML 或 JSON 相媲美的文本格式化语言。

      【讨论】:

        猜你喜欢
        • 2016-03-06
        • 2021-07-20
        • 2018-11-06
        • 2018-12-30
        • 2020-08-05
        • 2017-04-04
        • 2019-12-19
        • 2022-01-09
        • 2020-06-09
        相关资源
        最近更新 更多