在我的应用程序中,我使用泛型DAO模式。我的班级结构如下:
当我试图启动服务器时,我会看到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [com.test.abc.h.INameDAO] found for dependency: expected at
least 1 bean which qualifies as autowire candidate for this dependency. Dependency
annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}我在这里错过了什么?我尝试将@Repository注释添加到INameDAO以及Name域类中。这没什么用。还在名称域类中添加了@Component注释--这也没有帮助。
发布于 2014-02-10 06:45:31
您的INameDao是接口,而INameDao没有实现任何类作为您的代码。@Autowired用于注入依赖关系,@Autowires没有找到任何INameDao实现类。因此,您需要首先创建INameDao的Impl类。您的例外是NoSuchBeanDefinitionException,所以spring没有找到任何com.test.abc.h.INameDAO类型的合格bean。
发布于 2013-10-15 00:32:09
看起来您的GenericDAO是IGenericDAO类型的,但是您的错误表明您正在注入一个INameDAO类型的bean。虽然INameDAO是IGenericDAO类型的,但是GenericDAO不是INameDAO类型的。您需要修复GenericDAO的继承树,或者更改要注入的bean的类型,以便在其树中包含某些内容。
编辑
提供一个例子。这类似于定义java.util.Collection、java.util.List和java.util.Set。然后声明一个具有List属性的bean,并尝试注入一个集合。虽然他们有一个共同的祖先,但他们是不相容的。您可以将bean更改为接受Collection属性,但将仅限于Collection的方法。
使用下面的结构,您可以将MyActualDAOImpl注入到MyActualDAO类型的属性中(我已经不再使用泛型)。把你的NamedQueries on yourEntity`‘。
公共接口:
public interface GenericDAO{
//crud methods
}
public interface MyActualDao inherits GenericDAO{
//other non-crud methods, if needed
}实现
public abstract class AbstractDAO implements GenericDAO{
//generic implementations of CRUD
}
public MyActualDAOImpl inherits AbstractDAO implements MyActualDAO{
...
}https://stackoverflow.com/questions/19371233
复制相似问题