1. 程式人生 > >springboot原始碼分析6-springboot之PropertySource類初探

springboot原始碼分析6-springboot之PropertySource類初探

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的源頭就是一個MapPropertiesPropertySource的源頭就是一個Properties

name:我們可以理解為一個map中的key

PropertySource類的繼承結構圖如下圖所示:

 

l RandomValuePropertySourcesourcerandom

l ServletConfigPropertySourcesourceServletConfig

l ServletContextPropertySourcesourceServletContext

l JndiPropertySourcesourceJndiLocatorDelegate

l StubPropertySourcesourceObject

l MapPropertySourcesourceMap<String, Object>

本文內容暫時講解道這裡,後面的文章中講解環境變數的時候,再來一個個的看這些PropertySource子類。

未知引數最終被新增到了nonOptionArgs集合。

講解到這裡基本上命令列引數的設定以及解析原理都搞明白了。

歡迎關注我的微信公眾號,第一時間獲得部落格更新提醒,以及更多成體系的Java相關原創技術乾貨。 
掃一掃下方二維碼或者長按識別二維碼,即可關注。