标签:java spring abstract-class hibernate
我使用的是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,spring,abstract-class,hibernate 来源: https://codeday.me/bug/20190825/1723312.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。