是否有任何方法可以将变量的取反值分配给另一个变量,从而配置application.yml spring引导文件。有点像
org:
property: true
property2: !${org.property}
我尝试了几种方法,并且总是在抱怨。谢谢
在您的配置类中取消它:
@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可比的文本格式语言。