Spring Boot 2 Yaml属性工作,但在IDE中突出显示

时间:2018-08-24 12:17:01

标签: spring spring-boot yaml

我的Spring Boot应用程序中具有我的yaml配置,具有我的属性:

#app configs
my.messages.max_count: 5
my.messages.delay: 100
my.schedulers.charge_delay: 5000

它可以工作,但是IntellijIDE突出显示了以下内容并说:

Cannot resolve configuration property 'my.schedulers.charge_delay' less... (Ctrl+F1) 
Checks Spring Boot application .yaml configuration files. Highlights unresolved and deprecated configuration keys and invalid values. Works only for Spring Boot 1.2 or higher

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试一下:

my:
 messages:
  max_count: 5
  delay: 100
  charge_delay: 5000

... ....

您没有使用yml语法。

编辑:

您可以这样编写自己的Config类:

配置类:

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "my")
public class YamlConfig {

 private String delay;

 public String getDelay() {
     return url;
 }

 public void setDelay(String delay) {
     this.delay = delay;
 }
}

pom:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

yml:

my:
 delay: 5

最好的问候