@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. 前端知识总结--css用div画环形圆

    如何用最少的div画最多的环形?如下图所示最少需要多少个div? 暂时想到的利用div的边框.内外阴影及befor和after的伪元素实现 以下代码可以实现上图效果: <style> di ...

  2. 如何在阿里云上运行SAP UI5应用

    本来Jerry觉得这个知识点太简单了完全不值得写成微信公众号文章,但转念一想,可能网络上有一些刚刚初学UI5的朋友们可能会问到,所以还是写了. 今天一个成都同事问我这个问题,因为SAP WebIDE可 ...

  3. 9.Redis的Java客户端Jedis

    Redis的Java客户端Jedis Jedis所需jar包   commons-pool-1.6.jar jedis-2.1.0.jar 1.Jedis常用操作(jedis中的api 和 我们在 l ...

  4. 案例:selenium实现登录处理弹窗

    func.py https://www.cnblogs.com/andy9468/p/10899508.html main.py中 # 导入webdriver import os import tim ...

  5. Computer Vision_18_Image Stitching:A survey on image mosaicing techniques——2013

    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...

  6. JDK8 dockerfile

    # AlpineLinux with a glibc-2.28-r0 and Oracle Java 8FROM hub.devops.docker.com/library/alpine-glibc: ...

  7. linux 安装 wkhtmltox

    linux安装wkhtmltox wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox- ...

  8. MFC编程——Where is WinMain?

    源码 #include<afxwin.h> class MyApp :public CWinApp { public: virtual BOOL InitInstance(); }; My ...

  9. No result defined for action com.java.test.Action.HelloAction and result index

    Struts中配置action访问出错: Struts Problem Report Struts has detected an unhandled exception: Messages: No ...

  10. 15、TDM模型

    论文:https://arxiv.org/pdf/1801.02294.pdf 解析: 学习基于树的推荐系统深度模型 Learning Tree-based DeepModel for Recomme ...