title: Spring @autowired do not work if all classes are not in the same package
body: <p>I have four packages:</p>
  
  <ol>
  <li><p>com.spring.org       </p>
  
  <p>Files: <code>HomeController.java</code></p></li>
  <li><p>com.spring.org.dao </p>
  
  <p>Files: <code>SubscriberDao.java</code> , <code>SubscriberDaoImpl.java</code></p></li>
  <li><p>com.spring.org.model</p>
  
  <p>Files: <code>Subscriber.java</code> </p></li>
  <li><p>com.spring.org.service</p>
  
  <p>Files: <code>SubscriberService.java</code> , <code>SubscriberServiceImpl.java</code></p></li>
  </ol>
  
  <p>I put all my controller classes in <strong>com.spring.org</strong> package and others in different packages based on its type.  If I run my application I get this error message :</p>
  
  <p><strong>HTTP Status 500 - Servlet.init() for servlet appServlet threw exception</strong>
  <em>No qualifying bean of type [com.spring.org.service.SubscriberService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.....</em></p>
  
  <p>FYI: I am using autowired annoation in my Controller like following:</p>
  
  <pre><code>@Autowired
  private SubscriberService subService;
  </code></pre>
  
  <p>But if I put all my classes and interfaces in <strong>com.spring.org</strong> package then my application works perfectly.</p>
  
  <p>I have tried using these tags in my servlet-context.xml file to solve the problem, but still it did not work:</p>
  
  <pre><code>&lt;annotation-driven /&gt;
  &lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.spring.org.**" /&gt;
  &lt;context:component-scan base-package="com.spring.org.dao" /&gt;
  &lt;context:component-scan base-package="com.spring.org.model" /&gt;
  &lt;context:component-scan base-package="com.spring.org.service" /&gt;
  </code></pre>
  
  <p>I also tried only this:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.spring.org" /&gt;
  </code></pre>
  
  <p>You can see the code of my servlet-context.xml file here <a href="http://postimg.org/image/s6bnjccrn/" rel="nofollow">http://postimg.org/image/s6bnjccrn/</a></p>
  
  <p>Could you please tell me how to solve this problem ?</p>
  
  <p>Please let me know if you need to see any other files.</p>
  
  <h3>Update</h3>
  
  <p>My Code for SubscriberService :</p>
  
  <pre><code>@Service
  public interface SubscriberService {
  
   public void addSubscriber(Subscriber subscriber);
   public void updateSubscriber(Subscriber subscriber);
   public Subscriber getSubscriberById(int subId);
   public List&lt;Subscriber&gt; listSubs();
   public int removeSubscriber(int subId);    
  
  }
  </code></pre>
  
  <p>Root Cause</p>
  
  <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.spring.service.SubscriberService com.spring.org.HomeController.subService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.spring.service.SubscriberService] 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.Qualifier(value=)}
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)</p>
  
  <h3>Files</h3>
  
  <p>It would be very difficult to follow if I paste all my codes here, so I have upload my entire project here <a href="https://www.mediafire.com/?crxe7vt7uwyqwtl" rel="nofollow">https://www.mediafire.com/?crxe7vt7uwyqwtl</a>  . I am using Eclipse IDE.</p>