title: How to disable Spring autowiring in unit tests for @Configuration/@Bean usage
body: <p>I want configure a component test using spring-test configuration inner class (<code>@Configuration</code>). Tested components has some services which I'd like to mock for the test. These services are classes (no interface used) and have spring annotations (<code>@Autowired</code>) in them. Mockito can easily mock them, however, I found no way of disabling spring autowiring.</p>
  
  <p>Example how I can easily reproduce:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = SomeTest.Beans.class)
  public class SomeTest {
  
      // configured in component-config.xml, using ThirdPartyService
      @Autowired
      private TestedBean entryPoint;
  
      @Test
      public void test() {
      }
  
      @Configuration
      @ImportResource("/spring/component-config.xml")
      static class Beans {
          @Bean
          ThirdPartyService createThirdPartyService() {
              return mock(ThirdPartyService.class);
          }
      }
  }
  
  public class ThirdPartyService {
      @Autowired
      Foo bar;
  }
  
  public class TestedBean {
      @Autowired
      private ThirdPartyService service;
  }
  </code></pre>
  
  <p>In this example "TestBean" represents the service to be mocked. I would NOT like "bar" to be  injected by spring! <code>@Bean(autowire = NO)</code> does not help (in fact, that's the default value).
  (Please save me from "use interfaces!" comments - the mocked service can be 3rd party which I can't do anything with.)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Springockito partially solves the problem, as long as you don't have to have anything else to configure (so you can't use configuration class with Springockito - it does not support it), but use mocks only.
  Still looking for pure spring solution, if there's any...</p>