开发者

What is the difference between DAO and Spring Beans?

开发者 https://www.devze.com 2023-01-24 12:20 出处:网络
I\'m starting to program in Java (with the Spring Framework) and finding myself confused about t开发者_StackOverflowhe difference between DAOs and Spring\'s Beans. Do they serve to the same purpose?DA

I'm starting to program in Java (with the Spring Framework) and finding myself confused about t开发者_StackOverflowhe 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消