@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. c#基础知识梳理(五)

    上期回顾 - https://www.cnblogs.com/liu-jinxin/p/10831189.html 一.运算符重载 您可以重定义或重载 C# 中内置的运算符.因此,程序员也可以使用用户 ...

  2. Django rest-framework框架-content-type

    表结构讨论: 是用一张表价格策略表来记录两种不同的价格策略 content-type原理: 使用一张表来记录不同课程的价目,增加一行表名称 注释: 适用于多张表关联一张表的情况 会自动生成这种的结构: ...

  3. css之弹性盒模型

    弹性盒子(Flexible Box/filebox)是一种当页面需要适应不同的屏幕大小以及设备类型时确保元素拥有恰当的行为的布局方式.引入弹性盒布局模型的目的是提供一种更加有效的方式来对一个容器中的子 ...

  4. JS实现异步的几种方式

    1.JS执行环境:单线程   单线程:就是指一次只能完成一件任务.若有多个任务时,就必须排队,等前面一个任务完成之后,再执行后面一个任务 缺点:任务耗时很长,后面的任务需要等待,拖延整个程序的执行.例 ...

  5. webbrowser 屏蔽脚本错误

    webBrowser1.ScriptErrorsSuppressed = true

  6. Iterator 其实很简单(最好理解的工厂模式的例子)

    我们都知道Iterator是一个典型的工厂模式的例子.那么我们可能会被这两个名词搞晕.首先,我们会奇怪,为什么iterator可以遍历不同类型的结合,其次,出入程序猿的我们根本不知道工厂模式是什么. ...

  7. pytorch之nn.Conv1d详解

    转自:https://blog.csdn.net/sunny_xsc1994/article/details/82969867,感谢分享 pytorch之nn.Conv1d详解

  8. zabbix-将业务机器加入到监控中

    一.设置被监控的机器 1. 配置主机名 echo "agent.test.com" > /etc/hostname hostname agent.test.com 2.安装z ...

  9. strconv:各种数据类型和字符串之间的相互转换

    介绍 strconv包实现了基本数据类型和其对应字符串之间的相互转换.主要有一下常用函数:Atoi,Itoa,Parse系列,Formart系列,Append系列 string和int之间的转换 这一 ...

  10. deep_learning_Github_初学者教程

    Github_link_from:https://github.com/lawlite19/MachineLearning_Python 机器学习算法Python实现 目录 机器学习算法Python实 ...