Spring boot 读取properties
## Spring boot 读取properties 在开发中我们需要通过属性文件配置常用属性,例如数据库相关、日志相关、测试相关等。 自定义properties文件获取属性 application.properties获取属性 ### 自定义properties文件获取属性 使用@configurationProperties((prefix=”xxx.yyy”)) 和 @PropertySource(“classpath:xxxconfig.properties”) xxx.yyy表示的是属性文件中的前缀(有时候我们希望可以分的更清楚) 使用自定义的时候需要给类添加@Component 让Spring管理类的生命周期 在使用的地方使用@Autowired 让系统进行初始化 // PropertySource默认取application.properties // @PropertySource(value = “xxxconfig.properties”) 例如 “` @Component @ConfigurationProperties(prefix = “com.xxx”) @PropertySource(“classpath:myconfig.properties”) public class TestBean { private String host; public String getHost() { return host; } public void setHost(String host) { this.host = host; } } //使用地方 @Autowired private TestBean testBean “` ### application.properties获取属性 共有三种 参考上面自定义 只是不用设置PropertySource PropertySource默认取application.properties 使用@Value注解 使用Environment #### 使用@Value ...