0
点赞
收藏
分享

微信扫一扫

Spring Boot-@PropertySource注解


@PropertySource:加载自己手动编写的资源文件
有关@ConfigurationProperties注解的作用请访问​Spring Boot-@Value获取值和@ConfigurationProperties获取值的比较

//@Component:将组件注入到容器中
@PropertySource(value = {"classpath:person.properties"})
@Component
@ConfigurationProperties(prefix = "person")
public class Person {

private String lastName;
private Integer age;
private Boolean boss;
private Date date;


private Map<String,Object> map;

private List<Object> list;

private Student student;

public Student getStudent() {
return student;
}

public void setStudent(Student student) {
this.student = student;
}

person.properties

person.last-name=李四
person.age=20
person.date=2000/10/10
person.boss=false
person.map.k1=v1
person.map.k2=v2
person.list=a,b,c
person.student.name=lisi
person.student.age=13

测试

@SpringBootTest
class SpringBoot02ApplicationTests {

@Autowired
Person person;

@Test
void contextLoads() {
System.out.println(person);
}

}

结果:

Spring Boot-@PropertySource注解_spring boot


举报

相关推荐

0 条评论