title: JUnit test in Spring - overriding and ignoring beans from application other configuration classes
body: <p>We have large application written in Spring 3. I need to write JUnit test checking behavior of some service. It is not a unit but part of a system. There are some services and repositories working together insite it -> lot of injected beans inside. The app also uses aspects.</p>
  
  <p><strong>My question is. How to manage config and beans in this case of tests?</strong> I need to use beans defined in app configes and in tests only redefine beans using persistence to work with a embedded db. So I need to use beans from src as they are defined and override only some causing troubles (persistance beans, beans using webservices,...)
  In test package I made Config class definying beans for persistance, using datasource for hsql. But I don`t know what next. I tried to annotate Test config class with:</p>
  
  <pre><code>@Configuration
  @EnableAspectJAutoProxy
  @EnableTransactionManagement(mode = AdviceMode.ASPECTJ, proxyTargetClass = true)
  @ComponentScan(basePackages = "com.example.our.app")
  public class MyTestConfig implements TransactionManagementConfigurer {
  </code></pre>
  
  <p>to scan whole application and use configuration of beans from src folder. But this also takes configs from other tests causing problems. Is this whole good strategy or not? What now - use excludeFilters to remove other test configs? Or is this strategy whole bad? </p>
  
  <p>thanks</p>