+-
java – 抽象类的自动连接依赖项注入失败
我使用的是 Spring 3和Hibernate 4

我有以下类结构

public interface GenericDAO<T> {

    public void create(T entity);
    public void update(T entity);
    public void delete(T entity);
}

DAO班

public interface EmployeeDAO extends GenericDAO<Employee>  {

    public void findEmployee(EmployeeQueryData data);
}

DAO实现类

@Repository("employeeDAO")
public abstract class EmployeeDAOImpl implements EmployeeDAO {

protected EntityManager entityManager;

@Override
public void findEmployee(EmployeeQueryData data) {

...... code

}

我面临的问题是当我尝试部署时,我得到以下异常.
如果我从EmployeeDAOImpl中删除摘要并删除扩展GenericDAO< Employee>从EmployeeDAO然后应用程序部署没有错误.因此,不可能为EmployeeDAOImpl提供抽象类,或者我需要在没有抽象的DAO实现中实现GenericDAO的所有方法?

Error creating bean with 
name 'employeeService': Injection of autowired dependencies failed; \
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: test.dao.EmployeeDAO 
test.service.EmployeeServiceImpl.employeeDAO; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No matching bean of type [test.dao.EmployeeDAO] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for 
this dependency. Dependency annotations: 
{@javax.inject.Inject()}.

编辑1

GenericDAOImpl

public class GenericDAOImpl<T> implements GenericDAO<T> {    

    public void create(T entity) {
    }       
    public void update(T entity) {
    }
    public void delete(T entity) {
    }

EmployeeDAOImpl

public class EmployeeDAOImpl extends GenericDAOImpl<Employee> implements EmployeeDAO {
最佳答案
Java(以及Spring)不能创建抽象类的实例:在Java允许您创建实例之前,每个方法都必须有一个实现,否则当您尝试调用该方法时会遇到运行时错误.您需要从EmployeeDAOImpl中删除“abstract”并实现从GenericDAO继承的方法.
点击查看更多相关文章

转载注明原文:java – 抽象类的自动连接依赖项注入失败 - 乐贴网