Injection of autowired dependencies failed for abstract class

abstract-class, hibernate, java, spring

Solution

Java (and consequently Spring) cannot create instances of abstract classes: every method must have an implementation before Java will let you create an instance, otherwise you would get a runtime error when you tried to call the method. You need to remove "abstract" from EmployeeDAOImpl and implement the methods inherited from GenericDAO.

Problem

I am using Spring 3 and Hibernate 4 I have the following class structure ``` public interface GenericDAO<T> { public void create(T entity); public void update(T entity); public void delete(T entity); } ``` DAO class ``` public interface EmployeeDAO extends GenericDAO<Employee> { public void findEmployee(EmployeeQueryData data); } ``` DAO Implementation class ``` @Repository("employeeDAO") public abstract class EmployeeDAOImpl implements EmployeeDAO { protected EntityManager entityManager; @Override public void findEmployee(EmployeeQueryData data) { ...... code } ``` The problem I am facing is when I try to deploy, I am getting the following exception. If I remove `abstract` from `EmployeeDAOImpl` and remove `extends GenericDAO<Employee>` from `EmployeeDAO` then application gets deployed without errors. So it is not possible to have `abstract` class for `EmployeeDAOImpl` or I have need to implement all methods of `GenericDAO` in DAO implementation without `abstract`? ``` 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()}. ``` Edit 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 { ```

Original source