【发布时间】:2013-10-22 16:01:36
【问题描述】:
在我的应用程序中,我使用的是通用 DAO 模式。我的班级结构如下所示:
-
一个领域类——pojo
package com.test.abc.def; @NamedQueries({------a couple of queries go here .......}) @Entity @Table(name = "NAME") public class Name implements Serializable { private String myName; ........ @Column(name = "MY_NAME", nullable = false, length = 30) public String getMyName() { return this.myName; } public void setName(String myName) { this.myName= myName; } ........ } -
一个DAO接口,对应上面Domain类中的NamedQueries
package com.test.abc.h; public interface INameDao extends IGenericDAO<...., ....> { ....method signature...... } -
一个 IGenericDAO 接口
package com.test.abc.h; public interface IGenericDAO<T, PK extends Serializable> { ......... } -
GenericDAO 实现类
package com.test.abc.h.impl; @Repository @Scope( BeanDefinition.SCOPE_PROTOTYPE ) public class GenericDAO<T, PK extends Serializable> implements IGenericDAO<T, PK> { ....method implemnetations ........ } -
应用上下文:
<context:component-scan base-package="com.test.abc" /> <context:annotation-config /> <mvc:annotation-driven /> <mvc:default-servlet-handler /> -
服务类具有以下自动装配声明:
@Autowired private Name name; @Autowired private INameDAO nameDAO; ...... nameDAO.callToNamedQuery() - here I would like to call the named query present in Name class.
我在尝试启动服务器时看到以下错误:
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 域类。那没有帮助。 还在 Name 域类中添加了 @Component 注释 - 这也没有帮助。
【问题讨论】:
标签: spring annotations autowired hibernate-generic-dao