Spring3注解@Component、@Repository、@Service、@Controller区别

在Spring3中,@Repository、@Controller、@Service这三个注解和@Component注解的功能是一样的。采用前三个注解类只是为了区分Bean所属的不同层次。

@Repository注解一般对应持久成;

@Service注解一般对应业务成;

@Controller注解一般对应控制层(Web层),如struts2中的action和spring mvc中的controller。

如果在Web应用中采用经典的三层结构的话,最好在持久层、业务层和控制层分别采用 @Repository、@Service 和 @Controller 对分层中的类进行注释,而用 @Component 对那些比较中立的类进行注释。

posted @ 2014-04-19 23:14  blackcat_333  阅读(277)  评论(0编辑  收藏  举报