@Component:组件,表示此写上了此注解的bean,作为一个组件存在于容器中。这样的话别的地方就可以使用@Resource这个注解来把这个组件作为一个资源来使用了。初始化bean的名字为类名首字母小写

与@Component注解功能相同的注解有:@Repository,@Service,@Controller,@Component ,默认情况下Spring认为这4个注解会被认为是一个组件。

@Repository:数据层,一般放在Dao接口的实现类上

@Service:服务层,一般放在service接口的实现类上

@Controller:控制层,一般放在action上

例如:

1、配置包扫描器:

<context:component-scan base-package="com.fz.annotation"></context:component-scan>

2、Controller层

@Controller

public class UserController

3、Service层

@Service("userService")

public class UserService

4、Dao层

@Repository

public class UserDaoImpl implements UserDao

其中@Controller,@Component,@Service这些注解,如果默认括号里直接写("userService")的时候表示是value=

例如:@Service("userService") 和 @Service(value="userService") 是相等的

SpringAnnotation注解之@Component,@Repository,@Service,@Controller的更多相关文章

  1. @Component @Repository @Service @Controller

    Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...

  2. 从头认识Spring-2.7 自己主动检測Bean(1)-@Component @Repository @Service @Controller

    这一章节我们来讨论一下自己主动检測Bean. 1.domain 厨师类: package com.raylee.my_new_spring.my_new_spring.ch02.topic_1_19; ...

  3. [转]what’s the difference between @Component ,@Repository & @Service annotations in Spring

    原文地址:https://www.cnblogs.com/softidea/p/6070314.html @Component is equivalent to <bean> @Servi ...

  4. 【转载】@Component, @Repository, @Service的区别

    @Component, @Repository, @Service的区别 官网引用 引用spring的官方文档中的一段描述: 在Spring2.0之前的版本中,@Repository注解可以标记在任何 ...

  5. What's the difference between @Component, @Repository & @Service annotations in Spring?

    @Component is equivalent to <bean> @Service, @Controller , @Repository = {@Component + some mo ...

  6. @Component, @Repository, @Service,@Controller的区别

    @Component, @Service, @Controller, @Repository是spring注解,注解后可以被spring框架所扫描并注入到spring容器来进行管理 @Componen ...

  7. Spring-Boot-Bean的使用,@Repository,@Service,@Controller,@Component

    前言 在Spring MVC的时候,我们使用xml来配置bean,如今的Spring boot推荐我们使用元注解的发生,那就听Spring Boot的推荐,下面我就为大家来介绍下Spring Boot ...

  8. @Component, @Repository, @Service的区别

    注解 含义 @Component 最普通的组件,可以被注入到spring容器进行管理 @Repository 作用于持久层 @Service 作用于业务逻辑层 @Controller 作用于表现层(s ...

  9. @Repository , @Service , @Controller 和 @Component

    用Spring MVC时@Controller注解的类将变成一个Spring MVC的控制器. 不用Spring MVC的情况下, 这四个注解没有区别. 根据注解的语义, 注解在类上面可以提高代码的可 ...

随机推荐

  1. 简单封装get和jsonp

    /** * 向服务器发送GET请求. *  * @param {type} url * @param {type} async 是否异步调用 * @param {type} fnCallback 回调 ...

  2. JS正则表达式从入门到入土(2)—— 元字符和字符类

    元字符和字符类 元字符 正则表达式由两种基本字符类型组成: 1.原义(正常)文本字符:代表本身含义的字符,如:a.b.c.1.2.3等. 2.元字符:元字符是在正则表达式中有特殊含义的非字母字符,如\ ...

  3. c语言数据类型字节长度

    突然间就想到了long和int到底什么区别(发现有很多问题都是突然间想到的),然后百度.google各种查找,各种书籍:<C++ Primer>.<C程序设计语言>查看,终于明 ...

  4. Myeclipse中java项目转换为Web项目

    https://blog.csdn.net/u010097777/article/details/51281059 这两天工作安排做一个跳转页面,不过昨天发布自己的Tomact花了不少时间,给的项目添 ...

  5. iOS开发中的地图开发

    显示地图: 1.导入头文件 #import <MapKit/MapKit.h> 如果同时需要用户定位的话还需要 #import <CoreLocation/CoreLocation. ...

  6. [BZOJ1131]Sta

    Description 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N<=1000000 下面N-1条边. Output ...

  7. 搭建Nginx图片服务器(Linux)

    知识点: 在Linux系统上安装Nginx服务器,配置图片访问路径 通过ftp上传图片到,指定路径,通过浏览器访问指定路径中的图片 参考博客:http://blog.csdn.net/maoyuanm ...

  8. 在.Net中进行SQL Server数据库备份与还原操作实用类

    #region 类说明 //----------------------------------------------------------------------------- // // 项目 ...

  9. SPOJ104 HIGH - Highways

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  10. 关于http请求ContentType:application/x-www-form-urlencoded

    在又一次http请求过程中,模拟post请求提交form表单数据一直提示部分参数为空,后面检查发现是缺少ContentType:application/x-www-form-urlencoded的原因 ...