title: injecting mock beans into spring context for testing
body: <p>I know similar questions have been asked, e.g. <a href="https://stackoverflow.com/questions/565334/spring-beans-redefinition-in-unit-test-environment">here</a>, but having done a search, I've come upon a solution I'm much happier with <a href="http://forum.springsource.org/archive/index.php/t-46824.html" rel="nofollow noreferrer">here</a></p>
  
  <p>My only problem however, is that I'm not sure how to implement this solution.</p>
  
  <p>What I want to be able to do is via the HotswappableTargetSource override the bean definitions of select beans in my application context with my test versions and then run the test. </p>
  
  <p>Then for each test case I'd like to specify which beans I want to be hot swappable and then each test  must be able to create its own mock versions and swap those in, and be able to swap back again.</p>
  
  <p>I am able to get the Application Context the test is running with but what I don't know is how to configure a bean to be hot swappable. I know how to do it when configuring beans with xml but I don't want to go back to using xml to configure beans.</p>