title: Creating a new instance of a bean after each unit test
body: <p>I'm new to the spring framework and have a question about its dependency injection capabilities using the Spring Context.</p>
  
  <p>This is the class I am trying to write an integration test for:</p>
  
  <pre><code>public class UserService {
  
  private Validator validator;
  private UserRepository userRepository;
  private Encryptor encryptor;
  private MailService mailService;
  
  ...
  
  public void registerUser(User user) {
      user.setPassword(encryptor.encrypt(user.getPassword()));
  
      Errors errors = new BindException(user, "user");
      validator.validate(user, errors);
  
      if (errors.getErrorCount() == 0) {
          userRepository.addUser(user);
          mailService.sendMail(user.getEmail());
      }
  }
  </code></pre>
  
  <p>In my tests (using Mockito) I want to assure the four items are called so I create tests like:</p>
  
  <pre><code>public void testRegisterCallsValidateInValidator() {
      userService.registerUser(testUser);
      verify(userService.getValidator(), times(1)).validate(any(User.class), any(Errors.class));
  }
  </code></pre>
  
  <p>All tests however fail saying I invoked the method multiple times. My only guess is that the UserService bean gets created once at the beginning of all the tests but doesn't get reloaded after each test.</p>
  
  <p>In my test configuration I use the following xml to decide which beans to inject:</p>
  
  <pre><code>&lt;bean id="userService" class="be.kdg.coportio.services.UserService"&gt;
      &lt;property name="validator" ref="validator"/&gt;
      &lt;property name="userRepository" ref="userRepository"/&gt;
      &lt;property name="encryptor" ref="encryptor"/&gt;
      &lt;property name="mailService" ref="mailService"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Any ideas?</p>