title: Spring Boot Test - field injection raises NullPointerException
body: <p>I'm writing test for rest app in spring boot.</p>
  
  <p>But in my test, interface CategoryService in CategoryController cannot be autowired when running test and NullPointerException raised. </p>
  
  <p><strong>CategoryService is injected at field level.</strong> </p>
  
  <p>Here my classes:</p>
  
  <p><strong>CategoryController</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/v1/categories")
  public class CategoryController {
  
      @Autowired
      private CategoryService categoryService;
  
      @RequestMapping
      public List&lt;Category&gt; getAll() {
          return categoryService.findAll();
      }
  }
  </code></pre>
  
  <p><strong>CategoryService</strong></p>
  
  <pre><code>@Service
  public class CategoryServiceImpl implements CategoryService {
  
      @Autowired
      CategoryRepository categoryRepository;
  
      @Override
      public List&lt;Category&gt; findAll() {
          return categoryRepository.findAll();
      }
  }
  </code></pre>
  
  <p><strong>CategoryRepositoryImpl</strong></p>
  
  <pre><code>@Repository
  public class CategoryRepositoryImpl  implements CategoryRepository {
      @Override
      public List&lt;Category&gt; findAll() {
          ... 
      }
  
  }
  </code></pre>
  
  <p><strong>----- TEST ------</strong></p>
  
  <p><strong>AppTestConfig</strong></p>
  
  <pre><code>@Configuration
  public class AppTestConfig {
  
      @Bean
      public CategoryRepository categoryRepository() {
          return new TestCategoryRepository();
      }
  
      @Bean
      public CategoryService categoryService() {
          return new App.CategoryServiceImpl(); 
      }
  }
  </code></pre>
  
  <p><strong>CategoryControllerTest</strong></p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes =  {AppTestConfig.class})
  public class CategoryControllerTest {
  
      @Autowired
      private CategoryRepository categoryRepository;
  
      @Test
      public void testGetAll() throws Exception {
          CategoryController controller = new CategoryController();
          List&lt;Category&gt; categories = controller.getAll();
          assertEquals(categoryRepository.findAll().size(), categories.size());
      }
  }
  </code></pre>
  
  <p>With constructor injection, everything works fine. </p>
  
  <p>What's the problem?</p>