title: jUnit on a spring service class: No such bean definition
body: <p>EDIT2: I've managed to "fix" the issue... just removing the Autowired annotation and going with a setUp/tearDown configuration. So, to add to my question, why does without the autowired annotation works (the class finds the path) and with it don't? I'm doing something wrong with the test-context file?</p>
  
  <p>EDIT: I'm going to point out that what I'm trying to autowire is a class that implements two interfaces. I've seen around (forum posts) that you can't do this (So this could be the reason for my problem), but haven't managed to get to an actual, "official" answer.
  So, for what I've seen, I should "autowire" one refrence to one of the interface and another reference to the other interface, and Spring magically would undertand that I'm trying to test that specific implementation. Is that right? And if so, why?</p>
  
  <p>I'm working on the jUnit tests for a somewhat big J2EE project, no prior experience on Hibernate. I'm going package per package, using what mostly are pre-configured files to make the tests, so the exact details of the configuration are a bit blurred for me. But I'm not being unable to instantiate a defined class (which is marked as a service).</p>
  
  <p>I have this, the "to be tested" class:</p>
  
  <pre><code>package com.stackoverflow.business.service.impl;
  
  @service
  public class ClassA Implements InterfaceA&lt;BeanA&gt;, BeanB {
  /* Actual implementation of the class*/
  }
  </code></pre>
  
  <p>And then, this, the actual test class, please, don't mind the useless imports:</p>
  
  <pre><code>package com.stackoverflow.business.service.test;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.test.context.ContextConfiguration;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.stackoverflow.business.service.impl.ClassA;
  
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {
          "classpath:/spring/integration-core-config.xml",
          "classpath:/spring/app-custom-persistence-hibernate.xml", 
          "classpath:/spring/app-test-persistence-hibernate.xml",
          "classpath:/spring/app-custom-reporting.xml",
          "classpath:/spring/test-context.xml"})
  public class ClassATest{
  @Autowired
      private ClassA classATestInstance;
  /* Rest of the implementations*/
  }
  </code></pre>
  
  <p>AFAIK, the 4 first xml files are standard for testing. test-context.xml was added by me, in hopes that spring found what I was trying to test, with the following configuration (And it seems running the test without this xml results in the same error):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/beans 
                 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                 http://www.springframework.org/schema/tx 
                 http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                 http://www.springframework.org/schema/context
                 http://www.springframework.org/schema/context/spring-context-3.1.xsd
                 http://www.springframework.org/schema/aop 
                 http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"&gt;
  
      &lt;context:component-scan base-package="com.stackoverflow.business.service.impl" /&gt;   
  
      &lt;bean id="ClassATest" class="com.stackoverflow.business.service.impl"&gt;&lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Hope there's no typo there. The directions are correct and the package names are correct, but I'm getting a BeanCreationException when spring tries to create the ClassA instance (ClassATestInstance), telling me that it's not finding the ClasA bean.</p>
  
  <p>I have never tried to test a class with a @Service annotation, so I'm not sure even if I could/should do it, but with previous classes on the same package (although with no annotation), using the test-context.xml file to define the bean worked just fine.</p>
  
  <p>What I'm missing here?</p>
  
  <p>EDIT: Added exception text (Only the first line to avoid clutter):</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'com.stackoverflow.business.service.test.ClassATest' 
  Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
  Could not autowire field: private com.stackoverflow.business.service.impl.ClassA com.stackoverflow.business.service.test.ClassATest nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.stackoverflow.business.service.impl.ClassA] 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)}
  </code></pre>