简体   繁体   中英

Spring Bean and Autowire to datasource

Noob to Spring. I have 2 files: foo-servlet.xml which has the following statement:

    <bean id:"DAO" class="a.b.data.MyDAO"/>   

fooController.java has the following:

@Controller
public class FooController{
    @Autowired
    private FooDAO fooDAO;

    public void setFooDAO (FooDAO fooDAO){ this.fooDAO = fooDAO;}

My question: Is Spring actually replacing / injecting the definition of DAO in the servlet into my FooDAO? I'm trying to understand the 'tie-in' between the bean and how Spring know to substitute that file for my FooDAO in the controller.

Oh, and there is no mention of @Repository or @Component anywhere in this example code...

The XML looks kind of corrupted. I think it needs to be id=DAO As far as i know: Autowiring is either done via the type or the name and the type. So when MyDAO implements FooDao your bean will be considered for Autowiring. But this is just a guess. The code of the Daos and the rest of the configuration would be helpful to give a correct answer to this question. Understanding Spring @Autowired usage This might answer your question as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM