springboot源码分析6-springboot之PropertySource类初探
来源:互联网 发布:上海同济大学网络教育 编辑:程序博客网 时间:2024/05/31 06:21
摘要:本小节重点梳理一下PropertySource类的相关结构以及职责,本文的学习前提是学习了springboot源码分析5-springboot之命令行参数以及原理一文。
在springboot源码分析5-springboot之命令行参数以及原理一文中,我们看到了实例化Source类的时候,会去先实例化其父类SimpleCommandLinePropertySource。SimpleCommandLinePropertySource类的构造函数中直接解析了命令行参数以及值,然后返回封装好的CommandLineArgs实例对象。SimpleCommandLinePropertySource类的构造函数中会继续调用其父类CommandLinePropertySource,CommandLinePropertySource继续调用其父类EnumerablePropertySource,EnumerablePropertySource继续调用其父类PropertySource。PropertySource类是一个抽象基类。
1.1. PropertySource类
PropertySource类是一个抽象类,代码如下:
1 public abstract class PropertySource<T> {
2 protected final String name;
3 protected final T source;
4 }
getSource()方法:这个方法会返回得到属性源的源头。比如MapPropertySource的源头就是一个Map,PropertiesPropertySource的源头就是一个Properties。
name:我们可以理解为一个map中的key。
PropertySource类的继承结构图如下图所示:
l RandomValuePropertySource:source是random。
l ServletConfigPropertySource:source是ServletConfig。
l ServletContextPropertySource:source是ServletContext。
l JndiPropertySource:source是JndiLocatorDelegate。
l StubPropertySource:source是Object。
l MapPropertySource:source是Map<String, Object>。
本文内容暂时讲解道这里,后面的文章中讲解环境变量的时候,再来一个个的看这些PropertySource子类。
未知参数最终被添加到了nonOptionArgs集合。
讲解到这里基本上命令行参数的设置以及解析原理都搞明白了。
欢迎关注我的微信公众号,第一时间获得博客更新提醒,以及更多成体系的Java相关原创技术干货。
扫一扫下方二维码或者长按识别二维码,即可关注。
- springboot源码分析6-springboot之PropertySource类初探
- springboot源码分析14-ApplicationContextInitializer原理Springboot中PropertySource注解多环境支持以及原理
- springboot源码分析2-springboot 之banner定制以及原理
- springboot源码分析4-springboot之SpringFactoriesLoader使用
- springboot源码分析5-springboot之命令行参数以及原理
- springboot源码分析3-springboot之banner类架构以及原理
- SpringBoot源码分析之CommandLineRunner、ApplicationRunner
- SpringBoot RestTemplate源码分析
- springboot源码分析1-springboot版本号获取
- SpringBoot 初探
- 初探SpringBoot
- Springboot中PropertySource注解的使用
- SpringBoot | 异常配置源码分析
- springboot源码分析之环境属性构造过程1
- SpringBoot源码研究之Start
- SpringBoot源码解析之Config
- springboot源码分析10-ApplicationContextInitializer使用
- springboot源码分析11-ApplicationContextInitializer原理
- Spring Boot学习(三):开发新一代Spring Java应用
- Elasticsearch 5.x 字段折叠的使用
- KindEditor-编辑器设置图标的显示隐藏
- model.py下的Meta笔记
- mac搭建python环境及tensoflow
- springboot源码分析6-springboot之PropertySource类初探
- 命令行编译C语言Hello World的过程
- 栈及链栈常用函数
- mybatis在Mapper.xml文件中使用大于,小于时要用 > <
- 从B树、B+树、B*树谈到R 树
- C# aspx获取web.config中的key值
- 自定义View的视图刷新问题
- 数理逻辑习题集(6)
- Spring构建Web应用部署至Tomcat开发过程中的数据编码问题