springBoot啓動類

啓動類上,使用該註解,定義要掃描的包
@ComponentScan(value ={"com.hollycrm,com.csc"})
因爲@SpringBootApplication 會默認將掃描位置等於當前目錄。詳見@SpringBootApplication 的內容。
 
 
1.1 @SpringBootApplication
 
 
包含3個子註解
 
1.1.1
 @SpringBootConfiguration:Spring Boot的配置類;標註在某個類上,表示這是一個Spring Boot的配置類;
        @Configuration:配置類上來標註這個註解;配置類 ----- 配置文件;配置類也是容器中的一個組件;
            @Component 將類注入容器
 
1.1.2 自動 配置信息
@EnableAutoConfiguration                 Spring的底層註解@Import,給容器中導入一個組件
    @Import({EnableAutoConfigurationImportSelector.class}) 導入類
        EnableAutoConfigurationImportSelector extends AutoConfigurationImportSelector 中獲取
給容器中導入非常多的自動配置類(xxxAutoConfiguration)
 
其中方法 getCandidateConfigurations() 調用loadFactoryNames()
 
掃描所有jar包類路徑下  META-INF/spring.factories
把掃描到的這些文件的內容包裝成properties對象
從properties中獲取到EnableAutoConfiguration.class類(類名)對應的值,然後把他們添加在容器中。
 
 
1.1.3
 
掃描位置
@ComponentScan(excludeFilters = {        
   @Filter(type = FilterType.CUSTOM,classes = {TypeExcludeFilter.class}),
   @Filter(type = FilterType.CUSTOM,classes = {AutoConfigurationExcludeFilter.class})
})
 
默認是啓動類的當前及其子目錄。 也可自定義掃描包,在啓動類使用註解。
@ComponentScan(value ={"com.hollycrm","com.csc"})
@SpringBootApplication
 
發佈了29 篇原創文章 · 獲贊 9 · 訪問量 9293
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章