@Configuration

@ConfigurationProperties

不能单独使用必须使用带有可以实例化bena的注解比如:@Component或者组合了@Component的注解

@ConfigurationProperties配合@EnableConfigurationProperties使用

可以实现@ConfigurationProperties所注解类是否实例化,由@EnableConfigurationProperties所注解的类决定。

@Data
@ConfigurationProperties(prefix="my.test")
public class MyServerConfiguration {
private String name;
}

@Component
@EnableConfigurationProperties(MyServerConfiguration.class)
public class MyServerConfigutation2 { }

MyServerConfigutation2这个类如果没有实例化MyServerConfiguration这个配置类也不会实例化!

联合使用

@Configuration,@ConfigurationProperties配合@ConditionalOnProperty使用,实现效果:

@Configuration
@ConditionalOnProperty(prefix = "my.test", value = "enabled", havingValue = "true")
@EnableConfigurationProperties(MyServerConfiguration.class)
public class MyServerConfigutation2 { }
@Data
@ConfigurationProperties(prefix="my.test")
public class MyServerConfiguration {
private String name;
}

只有配置文件中指定了:my.test.enabled=true才会实例化MyServerConfigutation2 这个类,也就才会实例化MyServerConfiguration ;

@Configuration,@ConfigurationProperties,@EnableConfigurationProperties的更多相关文章

  1. springboot @ConfigurationProperties @EnableConfigurationProperties @Bean @ Component

    https://www.cnblogs.com/duanxz/p/4520571.html https://juejin.im/post/5cbeaa26e51d45789024d7e2 1. Bea ...

  2. springboot注解之@Import @Conditional @ImportResource @ConfigurationProperties @EnableConfigurationProperties

    1.包结构 2.主程序类 1 @SpringBootApplication(scanBasePackages={"com.atguigu"}) 2 public class Mai ...

  3. @ConfigurationProperties + @EnableConfigurationProperties

    1.ConfigurationProperties 在类上通过@ConfigurationProperties注解声明当前类为属性读取类. 举例: @ConfigurationProperties(p ...

  4. @Import @bean,@Conditional @ConfigurationProperties @EnableConfigurationProperties 注解使用

    一分钟学会spring注解之@Import注解http://blog.51cto.com/4247649/2118354 @Autowired与@Resource 注解的使用 https://www. ...

  5. 在Spring Boot中使用 @ConfigurationProperties 注解, @EnableConfigurationProperties

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

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

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

  7. SpringBoot之ConfigurationProperties 源码解读

    前言 ConfigurationProperties 是SpringBoot引入的一个和外部配置文件相关的注解类.它可以帮助我们更好的使用外置的配置文件属性. 源码解析 属性注入到Java类 @Tar ...

  8. SpringBoot @ConfigurationProperties详解

    文章目录 简介 添加依赖关系 一个简单的例子 属性嵌套 @ConfigurationProperties和@Bean 属性验证 属性转换 自定义Converter SpringBoot @Config ...

  9. Springboot 配置类( @Configuration) 不能使用@Value注解从application.propertyes中加载值以及Environment为null解决方案

    最近遇到个场景,需要在使用@Bean注解定义bean的时候为对象设置一些属性,比如扫描路径,因为路径经常发布新特性的时候需要修改,所以就计划着放在配置文件中,然后通过@ConfigurationPro ...

随机推荐

  1. MongoDB知识小结

    一.术语 RDBMS MongoDB 数据库 数据库 表格 集合 行 文档 列 字段 表联合 嵌套文档 主键 主键 (MongoDB 提供了 key 为 _id ) 数据库 数据库名可以是满足以下条件 ...

  2. 客户端相关知识学习(十二)之iOS H5交互Webview实现localStorage数据存储

    前言 最近有一个需求是和在app中前端本地存储相关的,所以恶补了一下相关知识 webView开启支持H5 LocalStorage存储 有些时候我们发现写的本地存储没有起作用,那是因为默认WebVie ...

  3. sql 批量插入

    create  PROCEDURE insertinto as begindeclare @id int;set @id=1;while @id<10begininsert into perso ...

  4. vue-cli搭建vue项目环境

    该篇文章是继https://www.cnblogs.com/qing-5/p/11321585.html来写 1.打开终端,输入指令"npm install --global vue-cli ...

  5. 字符串转json数组

    import net.sf.json.JSONArray;import net.sf.json.JSONObject; String content = inBankOdd.getContent(). ...

  6. SAP官方提供的人脸识别API

    https://api.sap.com/api/face_detection_api/resource 准备一张克里斯蒂亚诺 - 罗纳尔多的图片: 点击Choose File按钮,加载这些图片,然后点 ...

  7. shell取消键盘回显

    使用下面这个命令取消回显 stty -echo   使用下面这个命令打开回显   stty echo

  8. 2.Buffer 缓冲区

    /*缓冲区(Buffer)*/ Buffer 就像一个数组,可以保存多个相同类型的数据.根据数据类型不同(boolean 除外),有以下Buffer常用子类: /*ByteBuffer*/(常用) . ...

  9. 完整的ELK+filebeat+kafka笔记

    之前有写过elasticsearch集群和elk集群的博客, 都是基于docker的,使用docker-compose进行编排(K8S暂未掌握) 三台服务器搭建es集群:https://www.cnb ...

  10. webpack中环境变量的使用方法

    这节课讲解一下,在webpack打包过程中,怎么去使用一些环境变量. 首先我有一个打包配置的三个文件 "scripts": { "dev-build": &qu ...