In my application I am using generic DAO pattern. My class structure looks like this:
A domain class - 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; } ........ }
A DAO interface that corresponds to the NamedQueries in the above Domain class
package com.test.abc.h; public interface INameDao extends IGenericDAO<...., ....> { ....method signature...... }
A IGenericDAO interface
package com.test.abc.h; public interface IGenericDAO<T, PK extends Serializable> { ......... }
GenericDAO implementation class
package com.test.abc.h.impl; @Repository @Scope( BeanDefinition.SCOPE_PROTOTYPE ) public class GenericDAO<T, PK extends Serializable> implements IGenericDAO<T, PK> { ....method implemnetations ........ }
application context:
<context:component-scan base-package="com.test.abc" /> <context:annotation-config /> <mvc:annotation-driven /> <mvc:default-servlet-handler />
A service class has the following autowire declarations:
@Autowired private Name name; @Autowired private INameDAO nameDAO; ...... nameDAO.callToNamedQuery() - here I would like to call the named query present in Name class.
I see the below error when I try to startup the server:
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)}
What am I missing here? I tried adding the @Repository annotation to the INameDAO - and to the Name domain class as well. That did not help. Also added @Component annotation to the Name domain class - that did not help either.