我正在尝试使用 Spring Boot 自动配置功能并遇到问题。我创建了一个 github 存储库,以便能够轻松地重现“问题”:
git clone https://github.com/clembo590/issues.git --branch spring_boot_auto_configuration
Run Code Online (Sandbox Code Playgroud)
只需运行mvn clean install,您将获得我在描述中提到的所有日志。
我已经“启用”了debug=truespring boot 属性,以查看哪个“自动配置”已激活或未激活(如果它未激活,为什么它未激活)。
我还添加了一些日志来“记录已添加到 Spring Boot 上下文中的所有 bean”。
这是我的自动配置类。
@Configuration
@ComponentScan(basePackageClasses = MyClass.class)
@ConditionalOnBean(ObjectMapper.class)
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
public class CleaningAutoConfiguration {
@Bean
public Fake fake(){
return new Fake();
}
private static class Fake{
}
}
Run Code Online (Sandbox Code Playgroud)
第一个奇怪的事情是这个日志:
CleaningAutoConfiguration:
Did not match:
- @ConditionalOnBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) did not find any beans of type com.fasterxml.jackson.databind.ObjectMapper (OnBeanCondition)
Matched:
- @ConditionalOnBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found bean …Run Code Online (Sandbox Code Playgroud)