Why component scanning does not work for Spring Boot unit tests?
The service class FooServiceImpl is annotated with @Service aka @Component which makes it eligible for autowiring. Why this class is not being picked up and autowired during unit tests? @Service public class FooServiceImpl implements FooService { @Override public String reverse(String bar) { return new StringBuilder(bar).reverse().toString(); } } @RunWith(SpringRunner.class) //@SpringBootTest public class FooServiceTest { @Autowired private FooService fooService; @Test public void reverseStringShouldReverseAnyString() { String reverse = fooService.reverse("hello"); assertThat(reverse)