转自:https://www.jianshu.com/p/e99bda52f878
1.首先增加pom文件的spring-boot-configuration-processor依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2.在需要使用自定义属性的类上增加@ConfigurationProperties(prefix = "xxx")的注解
@ConfigurationProperties(prefix = "person")
public class Person {
}
3.在启动类增加@EnableConfigurationProperties注解
@SpringBootApplication
@EnableConfigurationProperties
public class SpringBootYamlConfigApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootYamlConfigApplication.class, args);
}
}
4. 如果resources文件夹下没有application.yaml的话新建下,之后就可以使用idea的提示