標籤:missing 指定 level 怎樣 condition ota 匯入 ade actor
一、日誌配置
Spring Boot支援多種日誌架構,預設使用LogBack作為日誌架構。
配置記錄層級:
- 格式:logging.level.報名=層級
- 例如:logging.level.org.springframework.web=debug
配置記錄檔:
二、Profile
profile是spring根據不同環境來提供支援的。
- 全域的Profile設定檔使用格式:application-{profile}.properties
- 通過application.properties中的命令spring.profiles.active=dev來指定環境(dev:開發環境;prod:生產環境)
三、Spring Boot運行原理
Spring Boot不管怎樣,都繞不開@SpringBootApplication註解。該註解是一個組合註解,它的核心功能是由@EnableAutoConfiguration提供的。
上面便是它的源碼。它的核心註解便是@Import,功能為註解匯入。
EnableAutoConfigurationImportSelector使用SpringFactoriesLoader.loadFactoryNames方法來掃描META-INF/spring.factories檔案,將該設定檔中的配置載入到Spring容器。
(Spring Boot在進行SpringApplication對象執行個體化時會載入META-INF/spring.factories檔案,將該設定檔中的配置載入到Spring容器。)
四、條件註解
開啟任意一個AutoConfiguration檔案,一般都可以發現一些條件註解。
下面是常用的一些條件註解:
|
|
當容器有指定的Bean的條件下 |
| @ConditionalOnClass |
當類路徑下有指定的類的條件下 |
| @COnditionalOnExpression |
基於SpEL運算式作為判斷條件 |
| @ConditionalOnMissingBean |
當類路徑下沒有指定的類的條件下 |
| @ConditionalOnMissingClass |
當類路徑下沒有指定的類的條件下 |
這些註解都是組合了@Conditional註解,知識使用了不同的條件。
Spring Boot學習(五)