通过在配置文件中设置debug属性为true,让控制台打印自动配置报告,就可以查看自动配置类的生效情况。
1. 首先设置配置文件:
.yml
文件
debug: true
# -------------
server:
port: 8088
.properties
文件
debug=true
# -------------
server.port=8088
2. 查看控制台输出:
输出分为四种:
Positive matches
匹配生效的配置类;
CodecsAutoConfiguration matched:
- @ConditionalOnClass found required class 'org.springframework.http.codec.CodecConfigurer' (OnClassCondition)
CodecsAutoConfiguration.JacksonCodecConfiguration matched:
- @ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)
...
Negative matches
未匹配生效的配置类;
ActiveMQAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'javax.jms.ConnectionFactory' (OnClassCondition)
AopAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'org.aspectj.lang.annotation.Aspect' (OnClassCondition)
...
Exclusions
被排除的配置类(无特殊设置情况下为None);Unconditional classes
无条件配置类(即基本配置类,不需要匹配条件,默认生效)。
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration