@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. pycharm 小知识

    pycharm使用过程小知识: 1.pycharm定义项目或脚本抬头模版:setting ——Editor——File and Code Templates,右侧选择Python Script: 2. ...

  2. vultr VPS安装BBR

    1.安装 wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh chmod +x bbr.s ...

  3. 20145335郝昊《Java程序设计》课程总结

    20145335郝昊<Java程序设计>课程总结 1.读书笔记汇总 第一周学习总结:http://www.cnblogs.com/20145335hh/p/5244638.html 第二周 ...

  4. chrome调试工具

    Chrome调试面板 Chrome 开发者工具是一套内置在Google Chrome中Web开发和调试工具.使用开发者工具来重演,调试和剖析您的网站.其中常用的有Elements(元素面板).Cons ...

  5. PAT1072. Gas Station (30)

    题目的测试用例数据有问题! 第一个Case 应该是 G1 2.0 3.2 一直在想3.3分母的3怎么来了.ORZ #include <iostream> #include <ccty ...

  6. SQL Server----解决SQL Server 配置管理器不见了

    错误重现: 之前安装好的SQL Server 2012打开都没有问题,好多天没有打开了,今天打开我的SQL Server 2012 连接时出现错误: 在与SQL Server 建立连接时出现与网络相关 ...

  7. Uncaught SyntaxError: Unexpected end of input 突然报了这个错

    最后排查:把 return true 注掉好了,接着在打开注释,依然不报错.最后不报错了.0.0 ~~~

  8. Java之聊天室系统设计二

    服务器端: 浏览器端:

  9. java socket 判断Socket连接失效

    要判断socket连接链路是否可用时,不能通过socket.isClosed() 和 socket.isConnected() 方法判断,要通过心跳包 socket.sendUrgentData(0x ...

  10. IntelliJ IDEA 左侧显示/展开类中的方法

    困扰我很久的问题: project直接右键: 打开.关闭对应效果: 之前查到的都是 : 虽然也有类似的功能,但是展开的是右侧窗口中,打开的那个类的: 即使不是我想要的,但也是不错的功能!