@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. Xamarin开发综述

    https://blog.csdn.net/qq_41647999/article/details/84844357 一. 前言这十来天对Xamarin的学习踩了很多的坑,说来也是一把心酸泪,下面为大 ...

  2. pyodbc报错pyodbc.InterfaceError

    connection = pyodbc.connect(r'Driver={SQL Server Native Client 11.0};Server=...;Database=...;Trusted ...

  3. 6.Redis的事务

    Redis的事务(Redis部分支持事务) a)是什么 可以一次执行多个命令,本质是一组命令的集合.一个事务中的所有命令都会序列化,按顺序地串行化执行而不会被其它命令插入,不许加塞 b)能干吗 一个( ...

  4. GC案例

    FGC----jmap -histo:live导致 线上某服务的老年代配置了CMS,但却在gc.log发现连续Full GC的问题.JVM参数配置如下: -XX:+UseCMSInitiatingOc ...

  5. shell 数组介绍

    平时的定义a=1;b=2;c=3,变量如果多了,再一个一个定义很繁琐,并且取变量值也很累.简单的说,数组就是各种数据类型的元素按一定顺序排列的集合. 数组就是把有限个元素变量或数组用一个名字命名,然后 ...

  6. c语言的函数指针和函数指针数组的简单demo

    今天,简单记录一下,函数指针和函数指针数组的使用,废话不多说,直接贴上代码,里面有详细的注释,方便以后查阅. #include <cstdio> #include <Windows. ...

  7. mongodb索引简介

    上面讲解了数据的查询和索引的简单使用,并且说明索引可以显著的加快查询速度,实际上查询的种类有很多,与之对应的索引的种类也有很多,接下来会与索引一起,在说明索引种类的同时,详细介绍下查询的参数 1.索引 ...

  8. i p _ i n s e r t o p t i o n s函数

    i p _ o u t p u t函数接收一个分组和选项.当 i p _ f o r w a r d调用该函数时,选项已经是分组的一部分,所以 i p _ f o r w a r d总是把一个空选项指 ...

  9. Java集合--WeakHashMap

    转载请注明出处:http://www.cnblogs.com/skywang12345/admin/EditPosts.aspx?postid=3311092 第1部分 WeakHashMap介绍 W ...

  10. Java8-Annotations

    import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.an ...