Spring: @WebMvcTest + @ComponentScan

If you need to use @ComponentScan in your spring boot application, be aware that it will break your @WebMvcTest….unless you add defaults filters from the @SpringBootApplication annotation declaration

@SpringBootApplication
@ComponentScan(
    basePackages = {"x.y.z"},
    excludeFilters = {
        @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class)}
)
public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}
Advertisements