7

I want to exclude some packages from being scanned when using spring @SpringBootTest in the same way it is done with @ComponentScan. Is there something like

@SpringBootTest(excludeFilters =@ComponentScan.Filter(
            type = FilterType.REGEX,
            pattern = "package\\.\\.to\\.Exclude.*"))
Gama11
  • 31,714
  • 9
  • 78
  • 100
gkatzioura
  • 2,655
  • 2
  • 26
  • 39

1 Answers1

8

It seems that the best workaround on this is to create a class annotated with the @SpringBootApplication and configure the scanning configuration there

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackageClasses ={TestConfiguration.class})
public class TestApp {
}

Then your unit test you should specify the test class created previously

@SpringBootTest(classes = TestApp.class)
public class UnitTestClass {
}
Gama11
  • 31,714
  • 9
  • 78
  • 100
gkatzioura
  • 2,655
  • 2
  • 26
  • 39