@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. 前端虚拟接口mockjs的使用

    最近在学习VueJS,也进一步学习了ES6,看了一遍之后,难免手痒,所以想仿写点什么,但是数据是个问题,你总不能写个分页,写个轮播吧,但是在公司做自己的东西找后台要接口也不那么像回事,怎么办呢? 无意 ...

  2. IIS如何确定请求的处理程序

    1. 给定一个url请求,IIS需要确定它的文件名,扩展名,以及最相似的与本请求资源合适的"ScriptMaps"metadata (缓存的ISAPI扩展 - 应用程序扩展名映射列 ...

  3. Django---ModelForm详解

    示例: from django.db import models from django.forms import ModelForm TITLE_CHOICES = ( ('MR', 'Mr.'), ...

  4. linux第四周

    一.知识点总结 (一)用户态.内核态和中断 1.内核态:在高的执行级别下,代码可以执行特权指令,访问任意的物理地址,这时的CPU就对应内核态 2.用户态:在低级别的指令状态下,代码 只能在级别允许的特 ...

  5. logstash在Windows2008简单配置实例

    Windows2008 安装java1.8,配置系统环境变量: 官方下载并安装略...然后配置 logstash的配置文件 注意PATH路径名称不支持中文 input { file { type =& ...

  6. 【Semantic Segmentation】DeepLab V3(转)

    原文地址:DeepLabv3 代码: TensorFlow Abstract DeepLabv3进一步探讨空洞卷积,这是一个在语义分割任务中:可以调整滤波器视野.控制卷积神经网络计算的特征响应分辨率的 ...

  7. STL list用法总结

    2017-08-20 15:17:30 writer:pprp list是一种线性复杂度的容器,很快 /* name : usage of List writer : pprp declare : n ...

  8. spring boot 笔记--第三章

    spring boot 笔记 第三章,使用Spring boot 构建系统: 强烈建议支持依赖管理的构建系统,Maven或Gradle 依赖管理: Spring Boot的每版本都会提供它支持的依赖列 ...

  9. string与位运算

    1.String String  a="abc";  会在常量池中开辟一个空间,保存"abc" String  b=new String("abc&q ...

  10. 如何优雅地使用 rm 防止误删除?

    IT 界的有一个老梗,一次某论坛的数据库管理员抱怨自己老板一直虐待他,结果他一气之下就删库跑路了...... 于是... 据新华社北京 8 月 20 日电 ,北京一软件工程师徐某离职后因公司未能如期结 ...