spring boot 使用@ConfigurationProperties
来源:互联网 发布:高速收费查询软件 编辑:程序博客网 时间:2024/05/29 05:01
有时候有这样子的情景,我们想把配置文件的信息,读取并自动封装成实体类,这样子,我们在代码里面使用就轻松方便多了,这时候,我们就可以使用@ConfigurationProperties,它可以把同类的配置信息自动封装成实体类
首先在配置文件里面,这些信息是这样子滴
- 1
- 2
- 3
这时候我们可以定义一个实体类在装载配置文件信息
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
我们还可以把@ConfigurationProperties还可以直接定义在@bean的注解上,这是bean实体类就不用@Component和@ConfigurationProperties了
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
然后我们需要使用的时候就直接这样子注入
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
如果发现@ConfigurationPropertie不生效,有可能是项目的目录结构问题,你可以通过@EnableConfigurationProperties(ConnectionSettings.class)来明确指定需要用哪个实体类来装载配置信息。
阅读全文
0 0
- spring boot 使用@ConfigurationProperties
- spring boot 使用@ConfigurationProperties
- spring boot 使用@ConfigurationProperties
- 在Spring Boot中使用 @ConfigurationProperties 注解
- spring boot:使用@ConfigurationProperties注解加载配置文件
- 在spring-boot中使用@ConfigurationProperties
- spring boot @ConfigurationProperties @EnableConfigurationProperties 配置注解使用
- Spring boot @ConfigurationProperties
- spring-boot @ConfigurationProperties脑洞真大
- Spring Boot 使用@ConfigurationProperties注解获取配置文件中的值
- Using @ConfigurationProperties in Spring Boot
- Spring boot源码分析-ConfigurationProperties
- spring boot 通过@Value,@ConfigurationProperties获取配置
- 学习Spring boot 注解 @Value @Component @ConfigurationProperties
- Spring Boot第四弹:Spring Boot之@Value和@ConfigurationProperties
- spring-boot配置(一):@Configuration,@ConfigurationProperties和application.yml
- Spring boot 通过@ConfigurationProperties和@PropertySource读取自定义配置文件信息
- 开始使用Spring Boot
- 必备数学知识
- RabbitMQ系列(一):Windows下RabbitMQ安装及入门
- Android Studio3.0开发JNI流程------JNI的类型和数据结构
- 重现Redis--数据结构与对象(三)
- Spine动画在Unity中的变色问题
- spring boot 使用@ConfigurationProperties
- JVM(五)对象的创建
- 关于java多线程的一篇不错的入门级文章
- 使用jieba提取文章主旨大意
- 01-常用对象API(集合框架-Map集合特点&常用方法) 02-常用对象API(集合框架-常用方法演示)1 2 3 4
- spring 学习总结.
- HBase 深入浅出
- rabbitMQ第二篇:java简单的实现RabbitMQ
- 分布式最通俗的解释,我自己的整理。