@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包以及它的子包
![](http://s10.sinaimg.cn/mw690/c29e92c3gx6DBbDnBQl59&690)
四个注解的区别:
@Service用于标注业务层组件、
@Controller用于标注控制层组件(如Struts中的action)
@Repository用于标注数据访问组件即DAO组件
@Component泛指组件,当组件不好归类的时候我们可以使用这个注解进行标注,(现在可以都用此注解)
@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泛指组件,当组件不好归类的时候我们可以使用这个注解进行标注,(现在可以都用此注解)
相关文章推荐
- @Component @Service @Controller @Repository注解使用
- @Service@Repository@Controller@Component注解的使用
- Spring注解@Component、@Repository、@Service、@Controller使用
- @Component @Service @Controller @Repository注解使用
- 使用component,repository,Service,controller注解
- Spring 注解@Component,@Service,@Controller,@Repository
- Spring注解@Component、@Repository、@Service、@Controller区别
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解@Component、@Repository、@Service、@Controller区别
- 使用 @Repository、@Service、@Controller 和 @Component 将类标识为 Bean
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier、@scope
- Spring常用注解@Component、@Controller、@ Service、@ Repository......
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析[转]
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring浅析之注解之一@Service、@Component、@Controller、@Repository
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- Spring 注解@Component,@Service,@Controller,@Repository
- SpringAnnotation注解之@Component,@Repository,@Service,@Controller