java – 抽象类的自动连接依赖项注入失败
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 抽象类的自动连接依赖项注入失败,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1780字,纯文字阅读大概需要3分钟。
内容图文
![java – 抽象类的自动连接依赖项注入失败](/upload/InfoBanner/zyjiaocheng/732/a54152896fe647b18acd0a0cec243a4a.jpg)
我使用的是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 – 抽象类的自动连接依赖项注入失败全部内容,希望文章能够帮你解决java – 抽象类的自动连接依赖项注入失败所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。