Spring注解@ConfigurationPropertie

@ConfigurationPropertie作用

参考的博客
springboot中@ConfigurationProperties注解的工作原理
@ConfigurationProperties是springboot新加入的注解,主要用于配置文件中的指定键值对映射到一个java实体类上
ConfigurationPropertiesBindingPostProcessor这个bean后置处理器,就是来处理bean属性的绑定的,这个bean后置处理器后文将称之为properties后置处理器。你需要知道以下几件事:
ioc容器context的enviroment.propertySources记录着系统属性、应用属性以及springboot的默认配置文件application.properties中的配置属性等。properties后置处理器就是从其中找到匹配的配置项绑定到bean的属性上去的。
属性绑定是有覆盖性的,操作系统环境变量可以覆盖配置文件application.properties, java系统属性可以覆盖操作系统环境变量。更多的可以 参考官网

指定application.properties前缀

@ConfigurationProperties(prefix = "doc")

指定properties

@ConfigurationProperties(locations = "classpath:mail.properties", ignoreUnknownFields = false, prefix = "mail")
原文地址:https://www.cnblogs.com/JuncaiF/p/11153262.html