@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. redis 简单命令操作

    一.概述: 在该系列的前几篇博客中,主要讲述的是与Redis数据类型相关的命令,如String.List.Set.Hashes和Sorted-Set.这些命令都具有一个共同点,即所有的操作都是针对与K ...

  2. linux下不同服务器间数据传输(wget,scp)

    一.wget是Linux下最常用的http/ftp文件下载工具1.wget断点续传,只需要加上-c参数即可,例如:代码:wget-chttp://www.abc.com/abc.zip-Oabc.zi ...

  3. ashx 方法模板

    ; ); //查询字符串拼接 string searchparams = DTRequest.GetQueryString("jsonstring"); fooddetail mo ...

  4. ONVIF学习-ONVIF开发框架搭建(C++)

    第一步.下载gsoap 从gsoap官网(http://www.genivia.com/products.html#notice)下载最新版gsoap(博主用的是gsoap_2.8.45).gsoap ...

  5. hadoop hdfs设置quota

    quota分为两种: 1. 目录下的文件数限制 2. 目录下的空间大小 //设置文件数 hdfs dfsadmin -setQuota 1000000 /user/jenkin //设置空间大小 hd ...

  6. 20145309《Java程序设计》第七周学习总结

    教材学习内容总结 第13章 时间与日期 13.1 认识时间与日期 13.1.1 时间的度量 格林威治时间(GMT) 世界时(UT) 国际原子时(TAI) 世界协调时间(UTC) Unix时间:Unix ...

  7. Android下点亮LED

    http://blog.csdn.net/cpj_phone/article/details/43562551

  8. COGS 723. [SDOI2007] 超级数组

    ★★☆   输入文件:arr.in   输出文件:arr.out   简单对比 时间限制:1 s   内存限制:3 MB  Source: SDOI2007 Day2[问题描述] 一般的数组大家都经常 ...

  9. Centos7 ActiveMQ 安装并配置为开机启动

    第一步, 环境准备 更新CentOS7 ,安装epel-release,安装JDK,关闭防火墙 # yum clean all && yum update# yum install - ...

  10. An Example for Javascript Function Scoping and Closure

    1. An Real World Example In the patron detail page of the CRM system I'm working with, there’re larg ...