【发布时间】:2020-04-16 22:25:19
【问题描述】:
有没有办法将一个变量的否定值分配给另一个变量,配置application.yml spring boot文件。 类似的东西
org:
property: true
property2: !${org.property}
我尝试了几种方法,但总是春天抱怨它。 谢谢
【问题讨论】:
标签: spring-boot yaml
有没有办法将一个变量的否定值分配给另一个变量,配置application.yml spring boot文件。 类似的东西
org:
property: true
property2: !${org.property}
我尝试了几种方法,但总是春天抱怨它。 谢谢
【问题讨论】:
标签: spring-boot yaml
在你的配置类中否定它:
@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
}
【讨论】:
您不能直接在 YAML 中执行任何逻辑,因为 YAML 只是一种可与 XML 或 JSON 相媲美的文本格式化语言。
【讨论】: