Springboot自動裝配

爲什麼說Springboot可以自動裝配呢

首先看,註解SpringBootApplication:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {

此註解彙總多個註解,其中點開EnableAutoConfiguration:

@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {

其導入了一個類:AutoConfigurationImportSelector就是核心了,這個類起着自動加載各種配置類的功能,如數據源,redis等

此類中selectImports方法則是核心函數,

獲取spring.factories中EnableAutoConfiguration所對應的Configuration類列表加載。

 

 

 

 

 

發現一個維護Qing Dao Internet Company black list,推廣一波

大傢伙看一看,查漏補缺:

https://github.com/QingDaoIT/BlackList/issues

 

還有一個資源地址:

https://blog.csdn.net/weixin_43222373/article/details/92075908

 

起初資本家開除不加班的員工,我沒有說話
——因爲我經常加班;

接着他們裁掉拒絕996的員工,我沒有說話
——因爲我年輕能扛;

然後他們辭退要加班費的員工,我沒有說話
——因爲我自願加班;

後來他們迫害因病住院的員工,我沒有說話
——因爲我身體健康;

最後當他們開始對付我的時候,
已經沒人能站起來爲我說話了。

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章