SpringAnnotation注解之@Component,@Repository,@Service,@Controller
@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的更多相关文章
- @Component @Repository @Service @Controller
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...
- 从头认识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; ...
- [转]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 ...
- 【转载】@Component, @Repository, @Service的区别
@Component, @Repository, @Service的区别 官网引用 引用spring的官方文档中的一段描述: 在Spring2.0之前的版本中,@Repository注解可以标记在任何 ...
- What's the difference between @Component, @Repository & @Service annotations in Spring?
@Component is equivalent to <bean> @Service, @Controller , @Repository = {@Component + some mo ...
- @Component, @Repository, @Service,@Controller的区别
@Component, @Service, @Controller, @Repository是spring注解,注解后可以被spring框架所扫描并注入到spring容器来进行管理 @Componen ...
- Spring-Boot-Bean的使用,@Repository,@Service,@Controller,@Component
前言 在Spring MVC的时候,我们使用xml来配置bean,如今的Spring boot推荐我们使用元注解的发生,那就听Spring Boot的推荐,下面我就为大家来介绍下Spring Boot ...
- @Component, @Repository, @Service的区别
注解 含义 @Component 最普通的组件,可以被注入到spring容器进行管理 @Repository 作用于持久层 @Service 作用于业务逻辑层 @Controller 作用于表现层(s ...
- @Repository , @Service , @Controller 和 @Component
用Spring MVC时@Controller注解的类将变成一个Spring MVC的控制器. 不用Spring MVC的情况下, 这四个注解没有区别. 根据注解的语义, 注解在类上面可以提高代码的可 ...
随机推荐
- 什么是阻塞式和非阻塞io流?
阻塞IO:socket 的阻塞模式意味着必须要做完IO 操作(包括错误)才会返回. 非阻塞IO:非阻塞模式下无论操作是否完成都会立刻返回,需要通过其他方式来判断具体操作是否成功. 两者区别: 所谓阻塞 ...
- Ubuntu16 安装Jira
参见:https://segmentfault.com/a/1190000008194333 https://www.ilanni.com/?p=12119烂泥:jira7.3/7.2安装.中文及破解 ...
- Windows下编译live555源码
Windos下编译live555源码 环境 Win7 64位 + VS2012 步骤 1)源码下载并解压 在官网上下载最新live555源码,并对其进行解压. 2)VS下建立工程项目 新建Win32项 ...
- Python3.x:pip命令安装第三方库,超时处理方案
Python3.x:pip命令安装第三方库,超时处理方案 问题: pip install splinter命令安装第三方库,报超时错误: raise ReadTimeoutError(self._po ...
- ECU
ECU(Electronic Control Unit)电子控制单元,又称“行车电脑”.“车载电脑”等.从用途上讲则是汽车专用微机控制器,也叫汽车专用单片机.它和普通的单片机一样,由微处理器(CPU) ...
- CentOS7系统安装及环境初始化
操作系统安装: 将网卡名称设置为eth*,不使用CentOS 7默认的网卡命名规则.所以需要在安装的时候,增加内核参数.1. 光标选择“Install CentOS 7” 2. 点击Tab,打开 ...
- mysql分库分表(二)
mysql分库分表 参考: https://www.cnblogs.com/dongruiha/p/6727783.html https://www.cnblogs.com/oldUncle/p/64 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online - 1011 A Cubic number and A Cubic Number
2017-09-17 17:12:11 writer:pprp 找规律,质数只有是两个相邻的立方数的差才能形成,公式就是3 * n * (n + 1) +1, 判断读入的数是不是满足 这次依然只是做了 ...
- Object.defineProperties——MEAN开发后台的Model层
Object.defineProperties是什么?有什么用? 这个问题比较听起来可能比较难以理解,确实我也是在项目中遇到的才会去想.以前看到<高级程序设计>的时候,有这么一种东西,定义 ...
- RabbitMQ入门(4)——路由(Routing)
这一篇我们将介绍如何订阅消息的一个子集.例如,我们只需要将日志中的error消息存储到日志文件中而将所有日志消息都在控制台打印出来. 绑定(Bindings) 在前面的例子中,我们创建了交换机和队列的 ...