您的位置:首页 > 其它

@Component @Service @Controller @Repository注解使用

2013-11-02 00:32 501 查看
阿里云服务器购买!

@Component 相当于实例化类的对象,相当于在配置文件中注入了一个bean

要使用自动扫描机制,我们在spring的配置文件中应该如下配置:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
注意:表示扫描com.fangleijiang包以及它的子包





四个注解的区别:

@Service用于标注业务层组件、

@Controller用于标注控制层组件(如Struts中的action)

@Repository用于标注数据访问组件即DAO组件

@Component泛指组件,当组件不好归类的时候我们可以使用这个注解进行标注,(现在可以都用此注解)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: