简体   繁体   中英

What is the difference between DAO and Spring Beans?

I'm starting to program in Java (with the Spring Framework) and finding myself confused about the difference between DAOs and Spring's Beans. Do they serve to the same purpose?

DAO == Data Access Object. It's one way to write a persistence layer.

Spring can manage DAO beans and lots of other kinds, like message-driven beans, services, web controllers, and anything else you can encapsulate into a bean.

Spring has three parts:

  1. Inversion of Control (IOC). Think of Spring as a big factory for creating and managing beans.
  2. Aspect-oriented programming (AOP). This is how Spring manages cross cutting concerns like logging, transactions, proxying, remoting, and other activities that otherwise would be littered throughout your application.
  3. Framework code, like the persistence templates for JDBC, Hibernate, TopLink, etc.; remoting; web MVC; etc. They write better code than we do - you get to just use it.

DAOs are a pattern concept ( http://www.oracle.com/technetwork/java/dataaccessobject-138824.html ).

Spring Beans are class instances managed by Spring.

Of course you can use Spring IOC to implement an application using DAOs.

DAOs are meant to abstract away how the application constructs a data object. More specifically, you can have an interface UserDAO and implement it as a UserHibernateDAO , UserIbatisDAO , UserFileDAO and have them return data in a single format from different sources.

Duffymo explained Spring.

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