Java Spring@Autowire失败,未找到依赖项错误类型的合格bean

Java Spring@Autowire失败,未找到依赖项错误类型的合格bean,java,spring,spring-mvc,javabeans,autowired,Java,Spring,Spring Mvc,Javabeans,Autowired,突然间,我无法“自动连线”更多的豆子。 我创建了一个报表实体 Report.java: package com.prime.technology.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persist

突然间,我无法“自动连线”更多的豆子。 我创建了一个报表实体

Report.java:

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="report")
public class Report {
...
}
然后我为这个实体创建了一个DAO实例

ReportDAO.java:

package com.prime.technology.dao;

import java.util.List;

import com.prime.technology.entity.Report;

public interface ReportDAO {
    
    public List<Report> getReports();
...
}
最后是错误:

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 <clinit>
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 ["http-nio-8080"]
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)
    ...
ReportDAO2.java:

package com.prime.technology.dao;

import java.util.List;

import com.prime.technology.entity.Report2;

public interface ReportDAO2 {
    
    public List<Report2> getReports();
...
}
package com.prime.technology.dao;
导入java.util.List;
导入com.prime.technology.entity.Report2;
公共接口报告DAO2{
公共列表getReports();
...
}
ReportDAOImpl2.java:

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<Report2> getReports() {
        ...
    }
...
}
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<Report2> getReports() {
        return reportDAO.getReports();
    }
...
}
package com.prime.technology.dao;
导入java.util.List;
导入org.hibernate.Session;
导入org.hibernate.SessionFactory;
导入org.hibernate.query.query;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Repository;
导入com.prime.technology.entity.Report2;
@存储库
公共类ReportDAOImpl2实现ReportDAO2{
@自动连线
私人会话工厂会话工厂;
@凌驾
公共列表getReports(){
...
}
...
}
ReportService2.java:

package com.prime.technology.service;

import java.util.List;

import com.prime.technology.entity.Report2;

public interface ReportService2 {

    public List<Report2> getReports();
...
}
package com.prime.technology.service;
导入java.util.List;
导入com.prime.technology.entity.Report2;
公共接口ReportService2{
公共列表getReports();
...
}
ReportServiceImpl2.java:

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<Report2> getReports() {
        ...
    }
...
}
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<Report2> getReports() {
        return reportDAO.getReports();
    }
...
}
package com.prime.technology.service;
导入java.text.ParseException;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入java.util.List;
导入java.util.TimeZone;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Service;
导入org.springframework.transaction.annotation.Transactional;
导入com.prime.technology.dao.ReportDAO2;
导入com.prime.technology.entity.Report2;
@服务
公共类ReportServiceImpl2实现ReportService2{
@自动连线
私人报告道2报告道;
@自动连线
私人订单服务;
@凌驾
@交易的
公共列表getReports(){
返回reportDAO.getReports();
}
...
}

我想问题是自己解决的

我所做的:

  • 我用@Service(“test2”)注释了ReportServiceImpl2.java类
  • 我创建了一个名为ReportServiceImpl3.java的新ReportService实现
  • 我用@Service(“test3”)注释了这个类
  • 在控制器中,我使用了@Qualifier(“test2”)注释 在我做了这件事之后,它起作用了。此外,我删除了reportserviceinmpl3.java,回到了代码的前一个状态,现在可以工作了

我想这是一个IDE(Eclipse)问题,它自己解决了。

上面显示的是ReportService的实现(以及其他实现),这些都很有效,但没有显示ReportService2的任何实现,这就是找不到的错误消息状态。是否用
@Service
ReportService2注释了
@Service
ReportService2它与ReportService完全相同,我将在短时间内添加snippets@DavidDeacu“它的实现情况如何?”斯图尔图斯克补充道
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<Report2> getReports() {
        ...
    }
...
}
package com.prime.technology.service;

import java.util.List;

import com.prime.technology.entity.Report2;

public interface ReportService2 {

    public List<Report2> getReports();
...
}
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<Report2> getReports() {
        return reportDAO.getReports();
    }
...
}