@ComponentScan in application class breaks @WebMvcTest and @SpringBootTest

限于喜欢 提交于 2019-12-06 06:14:07

Found the reason for this odd behavior.

This is the declaration of the @SpringBootApplication annotation:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
        @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {

As you can see the @ComponentScan annotation inside the @SpringBootApplication has the excludedFilters attribute specified.

When I added the @ComponentScan annotation directly in my application class I did not specify the default excludedFilters and that is why the behavior was different.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!