Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBootTest exclude packages from being scanned

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 [email protected](
            type = FilterType.REGEX,
            pattern = "package\\.\\.to\\.Exclude.*"))
like image 583
gkatzioura Avatar asked Jun 22 '18 17:06

gkatzioura


Video Answer


1 Answers

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 {
}
like image 200
gkatzioura Avatar answered Oct 21 '22 12:10

gkatzioura