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的情况下, 这四个注解没有区别. 根据注解的语义, 注解在类上面可以提高代码的可 ...
随机推荐
- JFreeChart的简单应用及乱码解决
一.JFreeChart介绍: JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP ...
- centos上传下载文件
1.在windows上安装SecureCRT 2.在centos上安装rzsz软件:yum install lrzsz 3.rz命令上传文件到centos 4.sz命令发送文件到windows
- spring中bean实例化时机以及整个运转方式
接上一篇文章,一般在servlet获取到请求之后 在service方法中就可以完成所有的请求处理以及返回,但是我们会采用更高级的MVC框架来做.也就是说所有的MVC框架入口就是serlvet中的ser ...
- 高通camera结构(摄像头基础介绍)
摄像头基础介绍 一.摄像头结构和工作原理. 拍摄景物通过镜头,将生成的光学图像投射到传感器上,然后光学图像被转换成电信号,电信号再经过模数转换变为数字信号,数字信号经过DSP加工处理,再被送到电脑中进 ...
- word里怎么删除某一列
光标定位在第二列第一个字的前面,然后按住Alt键,拖动鼠标,选中第二列字,松开Alt键,点击Delete键即可
- java for语句执行顺序
public class test{ public static void main(String[] args) { int i=0; for(printChar ...
- LeetCode——Find Largest Value in Each Tree Row
Question You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 ...
- 第五篇:Spark SQL Catalyst源码分析之Optimizer
/** Spark SQL源码分析系列文章*/ 前几篇文章介绍了Spark SQL的Catalyst的核心运行流程.SqlParser,和Analyzer 以及核心类库TreeNode,本文将详细讲解 ...
- 数据结构实习 Problem H 迷宫的最短路径
数据结构实习 Problem H 迷宫的最短路径 题目描述 设计一个算法找一条从迷宫入口到出口的最短路径. 输入 迷宫的行和列m n 迷宫的布局 输出 最短路径 样例输入 6 8 0 1 1 1 0 ...
- RK61 Keyboard Use
~ 打法: FN+shift+Esc / ? Alt Files Ctral <=> 上 下 左 右 打法:FN+shift 切换 解锁键盘 打法:FN+win 蓝牙连接 打法:FN+ ...