title: Spring override bean of another module
body: <p>In my multimodule project I have integration tests as seperate module. That tests have application jar added as dependency. Is it possible to override application bean definition from integration tests?</p>
  
  <p>In application I have following Bean (standard java mail sender configuration)</p>
  
  <pre><code>@Configuration
  public class MailConfiguration {
  
     @Bean
     public JavaMailSender javaMailService() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        //standard mail configuration using properties
     }
  }
  </code></pre>
  
  <p>Now all my integration tests extends BaseIntegrationTest that loads test configuration classess</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  @ContextConfiguration(classes = { AppTestConfiguration.class, MailTestConfiguration.class})
  public class BaseIntegrationTest {
  
  }
  </code></pre>
  
  <p>And finally in my MailTestConfiguration I define another JavaMailSender </p>
  
  <pre><code>@Primary
  @Bean
  @Profile(TestProfiles.MAIL_GREEN_SMTP)
  public JavaMailSender javaMailService() {
  
      JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
      javaMailSender.setHost("localhost");
      javaMailSender.setPort(3025);
  
      return javaMailSender;
  }
  </code></pre>
  
  <p>It is working when I run the tests from application itself. When I run the tests from another module the bean is not overriden. </p>
  
  <p>I am aware that AppConfiguration class defined inside application cannot component scan the integration tests config classes so I also load AppTestConfiguration.</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = {"..."})
  public class AppTestConfiguration extends AppConfiguration {
  
  }
  </code></pre>
  
  <p>How to make it work?</p>