1、application.properties值注入
(1)properties
#test settint
global.systemName=cccp2009
(2)实体类
@Value("${global.systemName}")
private String systemName;
2、自定义properties值注入
(1)properties
#test setting
author.bookName=springboot 开发
author.date=2018-11-14
(2)实体类
@Component
@ConfigurationProperties(prefix = "author")
@PropertySource("classpath:author.properties")
public class Global {
private String bookName;
private String date;
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
本文详细介绍了在SpringBoot中如何使用application.properties文件进行全局配置值的注入,以及如何通过自定义properties文件和实体类实现更灵活的属性配置。具体包括使用@Value和@ConfigurationProperties注解的方法。

被折叠的 条评论
为什么被折叠?



