我是使用Spring 3和Hibernate 4
我有以下的类结构
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实现类
@Repository("employeeDAO")
public abstract class EmployeeDAOImpl implements EmployeeDAO {
protected EntityManager entityManager;
@Override
public void findEmployee(EmployeeQueryData data) {
...... code
}
我遇到的问题是在部署时出现以下异常。如果我从
EmployeeDAOImpl
中删除abstract
并从EmployeeDAO
中删除extends GenericDAO<Employee>
,则应用程序可以无错误地部署。因此,在DAO实现中无法拥有EmployeeDAOImpl
的abstract
类,或者我需要在DAO实现中实现所有GenericDAO
的方法而没有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 {
abstract GenericDAOImpl<T> implements GenericDAO<T>
,并实现它,然后从GenericDAOImpl<Employee>
继承EmployeeDAOImpl
。 - user1516873findEmployee
的方法是特定于Employee
实体和EmployeeDAO
的。将其包含在GenericDAOImpl
中是个好主意吗? - JacobfindEmployee
明显应该在EmployeeDAO
而不是GenericDAO
中。 - user1516873GenericDAOImpl<T>
,在EmployeeDAOImpl
中,我通过以下方式扩展GenericDAOImpl
并实现EmployeeDAO
:public class EmployeeDAOImpl extends GenericDAOImpl<Employee> implements EmployeeDAO {
- Jacob