title: How to use @SpyBean and @MockBean in a regular Spring Framework project
body: <p>We use Spring Framework 4.3.14-RELEASE in out project. The structure of our application is as follows:</p>
  
  <pre><code>parent \
        module-one
        module-two
        ...
        module-n
  </code></pre>
  
  <p>Now we are trying to write some integration tests in one of the modules and we faced with the next problem: need to make spying on Spring Data JPA repository. 
  In Spring Boot we have <code>@SpyBean</code> and <code>@MockBean</code> annotations, but they are not available in regular Spring Framework. We are not been able to migrate to Spring Boot. </p>
  
  <p>We had an attempt to add <code>spring-boot-test</code> and <code>spring-boot-test-starter</code> to our project, but, what was obvious, it did not work: dependencies does not appear in the classpath. </p>
  
  <p>And my question is: is there a way to use these annotations in a regular project? Or maybe other ways to spy Spring Data JPA repositories? </p>
  
  <p><strong>UPDATE: Example</strong></p>
  
  <pre><code>@Service
  public void MegaService {
      @Autowired
      MegaRepository repository;
      // ....
  }
  
  public interface MegaRepository extends JpaRepository&lt;MegaModel, Long&gt; {
     // ...
  }
  
  @Configuration
  public class TestRepoConfiguration {
  
      @Bean
      MegaRepository megaRepository(MegaRepository repository) {
          return Mockito.spy(repository); // of course, it does not work
      }
  }
  
  @RunWith(SpringJUnit4ClassRunner.class)
  public class MegaIntegrationTest {
      @Autowired
      MegaRepository repository;
  
      public void testMegaLogic() {
          when(repository.findAll()).thenAnswer(invocation -&gt; {
               System.out.println("Hello, comrades");
               return invocation;
          });
      }
  }
  </code></pre>