title: Spring bean injection conflict src/main vs src/test
body: <p>I have two implementations for a given interface both are annotated with @Component.</p>
  <p>One implementation is in src/main -&gt; IImplementationCore.java
  Other implementation is in src/test -&gt; IImplementationTest.java</p>
  <p>I have a test class ABCTest.java in src/test which is annotated with</p>
  <blockquote>
  <p>@RunWith(SpringRunner.class), @SpringBootTest, @ContextConfiguration,
  @ComponentScan, @EnableAutoConfiguration</p>
  </blockquote>
  <p>I want this ABCTest.java to inject IImplementationCore while running the test. But it is injecting IImplementationTest.java.</p>
  <p>package structure:</p>
  <ul>
  <li>src
  <ul>
  <li>main
  <ul>
  <li>package
  <ul>
  <li>IImplementationCore.java</li>
  </ul>
  </li>
  </ul>
  </li>
  <li>test
  <ul>
  <li>package
  <ul>
  <li>IImplementationTest.java</li>
  </ul>
  </li>
  <li>package2
  <ul>
  <li>ABCTest.java</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>Solution I know:</p>
  <ul>
  <li>Annotating @Primary for IImplementationCore.java resolves the issue.</li>
  </ul>
  <p>I somehow do not like to force something as primary because it is being annotated as primary due to some bean conflict from src/test but not due to some real conflict in core implementations.
  what are my other options? What I am looking for is, is there a way to only consider beans from src/main but not from src/test? Or is there any better way?</p>