title: Spring @Autowire fails with No qualifying bean of type found for dependency error
body: <p>Suddenly i cant @Autowired any more beans.
  I created a Report entity</p>
  <p>Report.java :</p>
  <pre><code>package com.prime.technology.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name=&quot;report&quot;)
  public class Report {
  ...
  }
  </code></pre>
  <p>Then i created a DAO instance for this entity</p>
  <p>ReportDAO.java :</p>
  <pre><code>package com.prime.technology.dao;
  
  import java.util.List;
  
  import com.prime.technology.entity.Report;
  
  public interface ReportDAO {
      
      public List&lt;Report&gt; getReports();
  ...
  }
  </code></pre>
  <p>Then i created the implementation of this interface</p>
  <p>ReportDAOImpl.java :</p>
  <pre><code>package com.prime.technology.dao;
  
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.query.Query;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  import com.prime.technology.entity.Report;
  
  @Repository
  public class ReportDAOImpl implements ReportDAO {
  
      @Autowired
      private SessionFactory sessionFactory;
      
      @Override
      public List&lt;Report&gt; getReports() {
          ...
      }
  ...
  }
  </code></pre>
  <p>Then i created a service layer</p>
  <p>ReportService.java :</p>
  <pre><code>package com.prime.technology.service;
  
  import java.util.List;
  
  import com.prime.technology.entity.Report;
  
  public interface ReportService {
  
      public List&lt;Report&gt; getReports();
  ...
  }
  </code></pre>
  <p>ReportServiceImpl.java :</p>
  <pre><code>package com.prime.technology.service;
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.List;
  import java.util.TimeZone;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.prime.technology.dao.ReportDAO;
  import com.prime.technology.entity.Report;
  
  @Service
  public class ReportServiceImpl implements ReportService {
  
      @Autowired
      private ReportDAO reportDAO;
      
      @Autowired
      private OrderService orderService;
      
      @Override
      @Transactional
      public List&lt;Report&gt; getReports() {
          return reportDAO.getReports();
      }
  ...
  </code></pre>
  <p>Finally i @Autowired the ReportService interface in the Controller. Everything works perfect until here.
  After this i need to repeat the process for a different entity which is very similar, but i received an error.
  After hours of debugging i decided to copy each file that was mentioned above and to add a &quot;2&quot; at the end of each name.</p>
  <p>Controller.java :</p>
  <pre><code>package com.prime.technology.controller;
  
  import java.security.Principal;
  import java.util.Calendar;
  import java.util.List;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  
  import com.prime.technology.entity.Report;
  import com.prime.technology.entity.User;
  import com.prime.technology.service.ReportService;
  import com.prime.technology.service.ReportService2;
  import com.prime.technology.service.UserService;
  
  
  @Controller
  @RequestMapping(&quot;/HR&quot;)
  public class HrController {
      
      @Autowired
      private UserService userService;
      
      @Autowired
      private ReportService reportService;
  
      @Autowired
      private ReportService2 reportService2;
  ...
  }
  </code></pre>
  <p>Finally the error:</p>
  <pre><code>SEVERE: Servlet [dispatcher] in web application [/Prime-Technology] threw load() exception
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.prime.technology.service.ReportService2' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1504)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
      ...
  
  Mar 19, 2021 12:35:41 PM org.apache.jasper.servlet.TldScanner scanJars
  INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  Mar 19, 2021 12:35:41 PM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing Spring DispatcherServlet 'dispatcher'
  Mar 19, 2021 12:35:41 PM org.springframework.web.servlet.FrameworkServlet initServletBean
  INFO: Initializing Servlet 'dispatcher'
  Mar 19, 2021 12:35:43 PM org.hibernate.validator.internal.util.Version &lt;clinit&gt;
  INFO: HV000001: Hibernate Validator 6.1.6.Final
  Mar 19, 2021 12:35:44 PM org.springframework.web.servlet.FrameworkServlet initServletBean
  INFO: Completed initialization in 2856 ms
  Mar 19, 2021 12:35:44 PM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler [&quot;http-nio-8080&quot;]
  Mar 19, 2021 12:35:44 PM org.apache.catalina.startup.Catalina start
  INFO: Server startup in [19887] milliseconds
  Mar 19, 2021 12:35:45 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [jsp] in context with path [/Prime-Technology] threw exception
  java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      ...
  </code></pre>
  <p>I mention that i use full Java Configuration (no xml). For other beans its working perfectly i assume i dont have any problem in the configuration.
  Thanks in advance! i look forward for your advices!</p>
  <p>EDIT:
  Report2.java :</p>
  <pre><code>package com.prime.technology.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name=&quot;old-report&quot;)
  public class Report2 {
  ...
  }
  </code></pre>
  <p>ReportDAO2.java :</p>
  <pre><code>package com.prime.technology.dao;
  
  import java.util.List;
  
  import com.prime.technology.entity.Report2;
  
  public interface ReportDAO2 {
      
      public List&lt;Report2&gt; getReports();
  ...
  }
  </code></pre>
  <p>ReportDAOImpl2.java :</p>
  <pre><code>package com.prime.technology.dao;
  
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.query.Query;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  import com.prime.technology.entity.Report2;
  
  @Repository
  public class ReportDAOImpl2 implements ReportDAO2 {
  
      @Autowired
      private SessionFactory sessionFactory;
      
      @Override
      public List&lt;Report2&gt; getReports() {
          ...
      }
  ...
  }
  </code></pre>
  <p>ReportService2.java :</p>
  <pre><code>package com.prime.technology.service;
  
  import java.util.List;
  
  import com.prime.technology.entity.Report2;
  
  public interface ReportService2 {
  
      public List&lt;Report2&gt; getReports();
  ...
  }
  </code></pre>
  <p>ReportServiceImpl2.java :</p>
  <pre><code>package com.prime.technology.service;
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.List;
  import java.util.TimeZone;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.prime.technology.dao.ReportDAO2;
  import com.prime.technology.entity.Report2;
  
  @Service
  public class ReportServiceImpl2 implements ReportService2 {
  
      @Autowired
      private ReportDAO2 reportDAO;
      
      @Autowired
      private OrderService orderService;
      
      @Override
      @Transactional
      public List&lt;Report2&gt; getReports() {
          return reportDAO.getReports();
      }
  ...
  }
  </code></pre>