功能

  将属性文件与一个Java类绑定,属性文件中的变量与Java类中的成员变量一一对应,无需完全一致。

  如需将 @ConfigurationProperties 注解的目标类添加到Spring IOC容器中,可以

  • 使用 @Component 注解目标类,这样项目启动时会自动将该类添加到容器中。
  • 使用 @EnableConfigurationProperties 间接的将 @ConfigurationProperties 注解的目标类添加到容器中。讲的详细点就是,使用 @ConfigurationProperties 注解 类A,使用 @EnableConfigurationProperties(value =  类A.class) 注解类B,那么容器在加载类B的时候,会先加载类A到容器中,实现了间接的加载。

源码

package org.springframework.boot.context.properties;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; @Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ConfigurationProperties { /**
* 属性文件中变量的前缀
* 如果变量的全名是server.port,那么value==server。
*/
@AliasFor("prefix")
String value() default ""; /**
* 属性文件中变量的前缀
* 如果变量的全名是server.port,那么prefix==server。
*/
@AliasFor("value")
String prefix() default ""; /**
* 是否忽略类型不匹配的错误
*/
boolean ignoreInvalidFields() default false; /**
* 是否忽略属性变量对应的字段不存在的错误
*/
boolean ignoreUnknownFields() default true; }

@ConfigurationProperties的更多相关文章

  1. springboot @ConfigurationProperties

    Spring Boot 提供了一种方式 --类型安全的bean,能够根据类型校验和管理application中的bean.继续使用author做例子.配置放在author.properties文件中. ...

  2. SpringBoot(五):@ConfigurationProperties配置参数绑定

    在springmvc或其他ssh框架中如果我们要实现一个配置参数的加载,需要使用代码实现读取properties文件等操作,或者需要使用其他属性@value(name="username&q ...

  3. Spring Boot ConfigurationProperties validate

    使用@Query可以在自定义的查询方法上使用@Query来指定该方法要执行的查询语句,比如:@Query("select o from UserModel o where o.uuid=?1 ...

  4. 注解ConfigurationProperties注入yml配置文件中的数据

    在使用SpringBoot开发中需要将一些配置参数放在yml文件中定义,再通过Java类来引入这些配置参数 SpringBoot提供了一些注解来实现这个功能 ConfigurationProperti ...

  5. Spring Boot: Yaml配置文件 以及 @ConfigurationProperties属性获取

    Yaml配置文件 概述 Spring Boot在支持application.properties配置文件的同时,也支持application.yaml配置文件. 配置文件中的属性,可以通过: 通过@V ...

  6. springboot情操陶冶-@ConfigurationProperties注解解析

    承接前文springboot情操陶冶-@Configuration注解解析,本文将在前文的基础上阐述@ConfigurationProperties注解的使用 @ConfigurationProper ...

  7. @ConfigurationProperties注解取消location属性

    当我正在自学如何自定义properties配置文件,为了防止不必要的麻烦,重新创建了一个新的properties文件 fu.properties 然后在自定义的配置类中引入fu.properties/ ...

  8. 在Spring Boot中使用 @ConfigurationProperties 注解

    但 Spring Boot 提供了另一种方式 ,能够根据类型校验和管理application中的bean. 这里会介绍如何使用@ConfigurationProperties.继续使用mail做例子. ...

  9. Spring-boot中@ConfigurationProperties,@Value,@PropertySource

    1.利用@ConfigurationProperties获取配置的值,@ConfigurationProperties是springboot提供的基于安全类型的配置放置. application.pr ...

  10. SpringBoot自定义属性配置以及@ConfigurationProperties注解与@Value注解区别

    我们可以在application.properties中配置自定义的属性值,为了获取这些值,我们可以使用spring提供的@value注解,还可以使用springboot提供的@Configurati ...

随机推荐

  1. September Challenge 2017

    Little Chef and Sums 分析:水题,去维护一下前缀和以及后缀和就好,注意long long #include "iostream" #include " ...

  2. vue 之 折线图挤压

    当tab标签栏变动时,echarts图会发生挤,这种情况,发现是html容器的width=100%这个设置,变成了width=100px. 解决方式: 1.设置一个最小宽度,获取width的值,当这个 ...

  3. qpython 读入数据问题: EOF error with input / raw_input

    直接使用input会报错 EOF error with input / raw_input 原因是在qpy里console mode 命令行模式不是完全和pc上的命令行一致,所以input和raw_i ...

  4. 5、opencv中的绘图函数

    1.目标 a.学习使用 OpenCV 绘制不同几何图形 b. 你将会学习到这些函数: cv2.line(), cv2.circle(), cv2.rectangle(),cv2.ellipse(),c ...

  5. iis部署错误:HTTP 错误 500.21 - Internal Server Error

    将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序“PageHandlerFactory-Integr”在其模块列表中有一个错 ...

  6. Finding Comments in Source Code Using Regular Expressions

    Many text editors have advanced find (and replace) features. When I’m programming, I like to use an ...

  7. Kubernetes 集群日志管理

    Kubernetes 开发了一个 Elasticsearch 附加组件来实现集群的日志管理.这是一个 Elasticsearch.Fluentd 和 Kibana 的组合.Elasticsearch ...

  8. OVN学习(二)

    部署OVN实验环境 同OVN学习(一) L3网络 创建逻辑交换机和路由 ### Central节点 ### 创建逻辑交换机和路由器 # ovn-nbctl ls-add inside # ovn-nb ...

  9. iptable学习

    参考文档 朱双印个人日志 netfilter/iptables架构 位置 钩子函数/规则链 说明 数据包刚刚进入网络层的位置 PREROUTING 在这里处理目标地址转换 经过路由判断,数据包从内核流 ...

  10. 自定义Swap

    网上看到的一篇文章加深了对指针的了解,收藏一下 自定义的swap函数是一个老掉牙的问题,而这个问题对于理解指针和内存中的栈是很有帮助的 一般自定swap函数是这样的: 1.swap函数的功能是实现两个 ...