您的位置:首页 > 其它

@Component、@Service、@Constroller

2015-09-13 22:50 211 查看
@Component、@Service、@Constroller,@Repository,它们分别用于软件系统的不同层次:

@Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次。

@Service 通常作用在业务层,但是目前该功能与 @Component 相同。

@Constroller 通常作用在控制层,但是目前该功能与 @Component 相同

@Repository通常用于将数据访问层 (DAO 层 ) 的类标识为 Spring Bean

为了让 Spring 能够扫描类路径中的类并识别出 @Repository 注解,需要在 XML 配置文件中启用Bean 的自动扫描功能,这可以通过<context:component-scan/>实现

<beans … >
……
<context:component-scan base-package=”bookstore.dao” />
  ……
</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: