如何在spring boot application.yml中获得负值

问题描述 投票:0回答:2

是否有任何方法可以将变量的取反值分配给另一个变量,从而配置application.yml spring引导文件。有点像

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

我尝试了几种方法,并且总是在抱怨。谢谢

spring-boot yaml
2个回答
0
投票

在您的配置类中取消它:

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

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.