为什么我的 Bean 没有生效?怎么打开条件报告?怎么看懂 Positive 和 Negative?用户自己定义了 Bean 之后自动配置怎么变?这篇用 Spring Boot 4.0.8 的真实报告逐条读。
不加参数:输出里有 "CONDITIONS EVALUATION REPORT" = False,输出共 3 行 --debug:输出里有 "CONDITIONS EVALUATION REPORT" = True,输出共 283 行 -Ddebug=true:输出里有报告 = True 只调高 logging.level.org.springframework.boot.autoconfigure.logging=DEBUG:输出里有报告 = True
--debug 或调高一个日志器的级别。
Positive matches:23 项 Negative matches:37 项 Exclusions:0 项 Unconditional classes:0 项
Positive、Negative、Exclusions、Unconditional 四部分。
[Positive matches] JacksonAutoConfiguration#jacksonJsonMapper:
JacksonAutoConfiguration#jacksonJsonMapper matched:
- @ConditionalOnMissingBean (types: tools.jackson.databind.json.JsonMapper; SearchStrategy: all) did not find any beans (OnBeanCondition)
[Negative matches] WebMvcAutoConfiguration:
WebMvcAutoConfiguration:
Did not match:
- not a servlet web application (OnWebApplicationCondition)
Matched:
- @ConditionalOnClass found required classes 'jakarta.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigure
[Negative matches] MessageSourceAutoConfiguration:
MessageSourceAutoConfiguration:
Did not match:
- ResourceBundle did not find bundle with basename messages (MessageSourceAutoConfiguration.ResourceBundleCondition)
[Negative matches] ProjectInfoAutoConfiguration#buildProperties:
ProjectInfoAutoConfiguration#buildProperties:
Did not match:
- @ConditionalOnResource did not find resource '${spring.info.build.location:classpath:META-INF/build-info.properties}' (OnResourceCondition)
[Negative matches] Main#myMapper:
Main#myMapper:
Did not match:
- @ConditionalOnProperty (user.mapper) did not find property 'user.mapper' (OnPropertyCondition)每个没生效的原因都有一句具体的话。
用户没定义 → [Positive matches]
JacksonAutoConfiguration#jacksonJsonMapper matched:
- @ConditionalOnMissingBean (types: tools.jackson.databind.json.JsonMapper; SearchStrategy: all) did not find any beans (OnBeanCondition)
JacksonAutoConfiguration#jsonMapperBuilder matched:
用户定义了 myMapper → [Negative matches]
JacksonAutoConfiguration#jacksonJsonMapper:
Did not match:
- @ConditionalOnMissingBean (types: tools.jackson.databind.json.JsonMapper; SearchStrategy: all) found beans of type 'tools.jackson.databind.json.JsonMapper' myMapper (OnBeanCondition)报告指出是哪个 Bean 挡住了自动配置。
不加 --debug:3 次进程总用时(ms)[649, 629, 640] --debug:3 次进程总用时(ms)[612, 618, 628]
本机上看不出启动变慢。