title: Why can't I @Autowired my service directly in my test and why do I need to @Autowired the repository?
body: <p>I have a spring boot application with  <code>Repository</code>(s). </p>
  
  <p>I also use <code>@Service</code> and extend the <code>repository</code> in it.</p>
  
  <p>When I try to @Autowired the service I have: </p>
  
  <blockquote>
    <p>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.api.core.service.CountryService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  
  <p>It work fine if I <code>@Autowired</code> the repository.</p>
  
  <p>My test must look like this : </p>
  
  <pre><code>@SpringBootTest
  @ActiveProfiles("core")
  @ContextConfiguration(classes = { UserManagementConfig.class, UserManagementServiceConfig.class })
  @UserManagementTx
  @RunWith(SpringRunner.class)
  public class BlogPostContentImplTest {
      @Autowired
      private CountryService countryService;
      @Autowired
      private BlogPostContentRepository blogPostContentRepository;
      private BlogPostContentServiceImpl blogPostContentService;
      private BlogPostContent entity = new BlogPostContent();
      @Before
      public void setUp() throws Exception {
          blogPostContentService = new BlogPostContentServiceImpl(blogPostContentRepository);
          List&lt;Country&gt; countryList = countryService.findAll(null);
          entity = new BlogPostContent();
          entity.setId(1L);
          entity.setDescription("test");
          entity.setCountry(countryList.get(0));
          blogPostContentService.insert(entity);
      }
  
      @After
      public void tearDown() throws Exception {
          blogPostContentService.delete(entity.getId());
      }
  
      @Test
      public void findAll() throws Exception {
          assertThat(blogPostContentService.findAll(null).size()).isGreaterThan(0);
      }
  
  }
  </code></pre>
  
  <p>This is how I configure the context : </p>
  
  <pre><code>@Configuration
  @ComponentScan({
          UserManagementConfig.CONTEXT_CLASSPATH
  })
  public class UserManagementConfig {
      public static final String CONTEXT_CLASSPATH = "com.api.userManagement.config.context.**";
  }
  
  @Configuration
  @ComponentScan({
          UserManagementServiceConfig.CLASSPATH,
  })
  public class UserManagementServiceConfig {
  
      public static final String CLASSPATH = "com.api.userManagement.service.**";
  
  }
  </code></pre>