自定义配置文件参数在application可以直接识别Not registered via @EnableConfigurationProperties or marked as Spring component
看见很多开源项目的配置文件可以直接配置在application.yaml中,自己也想弄一个,怎么弄呢?
这是我的demo,你正常ConfigurationProperties会报错Not registered via @EnableConfigurationProperties or marked as Spring component
@Component
@ConfigurationProperties("zuul2")
public class Zuul2Properties {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private String password;
}
需要加一个这个。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
需要maven手动编译一下就能展示出来了、compile.实测好使
标签:String,配置文件,Spring,age,自定义,password,public,name From: https://www.cnblogs.com/q1359720840/p/17687213.html