I have a Spring-boot application with a custom filter, FilterRegistrationBean.
When creating this filter, during bean instantiation, i try to search all annotations of a specific type in the classpath with some code.
ClassPathScanningCandidateComponentProvider provider = createComponentScanner();
provider.findCandidateComponents("").stream()...
The call to findCandidateComponents throws a NoClassDefFoundError.
The application works during normal operation, but fails in unittest. My test class like:
@RunWith(SpringRunner.class)
@SpringBootTest
public class YadaYadaApplicationTests
{
@Test
public void contextLoads()
{
}
}
If I comment out "@SpringBootTest" i can run normally.
I guess it is something as the classpath is not the same when running unit test as when i run the application stand alone.
These are my dependencies:
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
What can I do to resolve this?