title: Autowired issue with Spring test
body: <p>I have spent hours trying to figure out why my code will thow the following exception.  At this point, I am hoping that someone can be more clever than I am as I am losing hope... ;)</p>
  
  <blockquote>
    <p>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.ls.forecast.jpa.ForecastElementService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Quali
    fier(value=main)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)</p>
  </blockquote>
  
  <p>I have looked at many threads/tutorials without luck. They all seem to have the same set up as mine.  I added @Service on the implementation of the service, I added a Qualifier, checked that ForecastElementServiceImpl actually implemented the interface ForecastElementService.</p>
  
  <p>Service interface:</p>
  
  <pre><code>public interface ForecastElementService {
  
  Collection&lt;ForecastElement&gt; retrieve(String date);
  Collection&lt;ForecastElement&gt; retrieve();
  }
  </code></pre>
  
  <p>interface implementation:</p>
  
  <pre><code>@Stateless
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  @Repository("forecastElementService")
  @Service
  public class ForecastElementServiceImpl implements ForecastElementService {
  
  @PersistenceContext
  protected EntityManager em;
  
  @Override
  @Cacheable("forecastElements")
  public Collection&lt;ForecastElement&gt; retrieve(String date) {
      String sql = null;
      if(date != null) {
          sql = " SELECT fe FROM ForecastElement fe JOIN FETCH fe.forecastType WHERE ?1 between fe.startDate and fe.endDate";
      } else {
          sql = " SELECT fe FROM ForecastElement fe JOIN FETCH fe.forecastType";
      }
      final TypedQuery&lt;ForecastElement&gt; query = em.createQuery(sql, ForecastElement.class);
  
      return query.getResultList();
  }
  
  @Override
  @Cacheable("forecastElements")
  public Collection&lt;ForecastElement&gt; retrieve() {
  
      return retrieve(null);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>context.xml:</p>
  
  <pre><code>&lt;bean id="forecastElementService" class="com.ls.forecast.jpa.ForecastElementServiceImpl"&gt;
  &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>AND finally the trouble test class - the forecastElementService variable is the one throwing the exception.</p>
  
  <pre><code>@Repository
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration({"*-context.xml"})
  public class ModelJpaTest extends AbstractTransactionalJUnit4SpringContextTests {
  
  //final Logger logger = LoggerFactory.getLogger(ModelJpaTest.class);
  
  @Autowired
  protected ForecastElementService forecastElementService;
  
  @Autowired
  @Qualifier("basicDataSource")
  @Override
  public void setDataSource(DataSource dataSource) {
      super.setDataSource(dataSource);
  }
  
  @Test
  public void LoadModelTest() {
      assertNotNull("forecastElementService is null", forecastElementService);
      Collection&lt;ForecastElement&gt; elements = forecastElementService.retrieve();
      assertTrue(elements.size() &gt; 0);
  }
  
  }
  </code></pre>
  
  <p>Any insight or help would be immensely appreciated!</p>
  
  <p>See @ContextConfiguration...  If I place the ModelJpaTest-context.xml in the resource (test) folder of my maven project and edit to:</p>
  
  <pre><code>@ContextConfiguration({"/ModelJpaTest-context.xml"})
  </code></pre>
  
  <p>Really confused by now... </p>