level 4
突然很无聊😞
楼主
Spring Boot提供的@ConfigurationProperties注解用来快速、方便地将配置文件中的自定义属性值批量注入到某个Bean对象的多个对应属性中。假设现在有一个配置文件,如果使用@ConfigurationProperties注入配置文件的属性,示例代码如下:
```java
@Component
@ConfigurationProperties(prefix ="person")
public class Person {
private int id;
// 属性的setXX()方法
public void setId(int id) {
this.id = id;
}
}
```
上述代码使用@Component和@ConfigurationProperties(prefix= “person”)将配置文件中的每个属性映射到person类组件中。
需要注意的是,使用@ConfigurationProperties
这些内容,是从拉勾教育的《Java工程师高薪训练营》里学到的,课程内容非常全面,还有拉勾的内推大厂服务,推荐你也看看。
2020年06月09日 06点06分
1
```java
@Component
@ConfigurationProperties(prefix ="person")
public class Person {
private int id;
// 属性的setXX()方法
public void setId(int id) {
this.id = id;
}
}
```
上述代码使用@Component和@ConfigurationProperties(prefix= “person”)将配置文件中的每个属性映射到person类组件中。
需要注意的是,使用@ConfigurationProperties