嗨,大家好我用hibernate和spring创建了一个简单的web应用程序,我想实现一个包含crud操作的抽象类,但是我有这个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientService' defined in class path resource [applicationContext.xml]:
Cannot resolve reference to bean 'clientDao' while setting bean property 'clientDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'clientDao' defined in class path resource [applicationContext.xml]:
Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.class]:
GenericDao
public interface GenericDao
}
GenericDaoImpl
@Transactional
public class GenericDaoImplsuper();
}
public GenericDaoImpl(Classsuper();
this.persistentClass = persistentClass;
}
@Transactional
public T save(T entity) {
this.sessionFactory.getCurrentSession().save(entity);
return null;
}
@Transactional
public T update(T entity) {
this.sessionFactory.getCurrentSession().update(entity);
return null;
}
@Transactional
public void delete(T entity) {
this.sessionFactory.getCurrentSession().delete(entity);
}
@SuppressWarnings("unchecked")
@Transactional
public T findById(ID id) {
return (T) this.sessionFactory.getCurrentSession().load(this.getPersistentClass(),id);
}
@SuppressWarnings("unchecked")
@Transactional
public Listcreatequery("* from"+this.getPersistentClass().getSimpleName()).list();
}
@Transactional
public void flush() {
this.sessionFactory.getCurrentSession().flush();
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Class
ClientDao
public interface ClientDao extends GenericDao
ClientDaoImpl
@Transactional
@Repository("clientDao")
public class ClientDaoImpl extends GenericDaoImpl
application context.xml
最佳答案
使用:
Spring会将字符串“强制转换”为类.然后,您可以从XML中删除客户端bean.
或者从ClientDaoImpl中删除此参数,因为它没用(它只能是这种类型,因此没有理由将其作为参数)
public ClientDaoImpl() {
super(com.xxx.Client.class);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。