title: Autowiring Spring services into JUnit tests
body: <p>Following is the service.</p>
  <pre><code>@Service
  public class MyService  {
     public List&lt;Integer&gt; getIds(Filter filter){
        // Method body
     }
  }
  </code></pre>
  <p>And a configuration class.</p>
  <pre><code>@Configuration
  public static class MyApplicationContext {
  
      @Bean
      public Filter filter(ApplicationContext context) {
          return new Filter();
      }
  }
  </code></pre>
  <p>The desired goal is a unit test to confirm <strong>getIds()</strong> returns the correct result.
  See the JUnit test below.</p>
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes=MyApplicationContext.class,                                                   
                        loader=AnnotationConfigContextLoader.class)
  public class AppTest
  {
      @Autowired
      Filter filter;
  
      @Autowired
      MyService service;
  }
  </code></pre>
  <p>The compiler finds the correct bean for the Filter class but throws a <code>BeanCreationException: Could not autowire field</code> exception for the service variable. I've tried adding the service class to the ContextConfiguration classes attribute but that results in a <code>IllegalStateException: Failed to load ApplicationContext</code> exception.</p>
  <p>How can I add MyService to ContextConfiguration?</p>