How to inject a DAO objecct to another DAO class in Spring 3

spring

Solution

Here I want to inject TestDAO2 class object to TestDAO1.java class. So I can use getArticleList() method. How can I do it ?

the same way as you inject one into controller - e.g. using `@Autowired` annotation:

public class TestDAO2 {
    @Autowired private TestDAO1 dao1;
    ....

there's no difference whether injected object is a service or another DAO.

Is it a right way OR standard to inject a DAO to DAO ?

in general: no. This situation indicates there may be some design issues in your model or DAO. perhaps your `TestDAO1` is doing too much? try moving this functionality into a service that uses both DAOs!

Problem

In my application I am using Spring3 MVC framework. I have a DAO class TestDAO1.java in which I need a method getArticleList() which is declared in TestDAO2.java class. As per my knowledge, we can inject Service layer objects to controllers and DAOs to Service layer. But can we inject a DAO object to a DAO class ? Here I want to inject TestDAO2 class object to TestDAO1.java class. So I can use getArticleList() method. How can I do it ? Is it a right way OR standard to inject a DAO to DAO ?

Original source