Spring中@Component的作用
今天在写程序的时候看见一个以前没有见过的注解(@Component),在网上查找过后,经过实践,决定把它记录下来。
1、@controller 控制器(注入服务)
- 用于标注控制层,相当于struts中的action层
2、@service 服务(注入dao)
- 用于标注服务层,主要用来进行业务的逻辑处理
3、@repository(实现dao访问)
- 用于标注数据访问层,也可以说用于标注数据访问组件,即DAO组件.
4、@component (把普通pojo实例化到spring容器中,相当于配置文件中的
<bean id="" class=""/>
)
- 泛指各种组件,就是说当我们的类不属于各种归类的时候(不属于@Controller、@Services等的时候),我们就可以使用@Component来标注这个类。
案例:
<context:component-scan base-package=”com.*”>
上面的这个例子是引入Component组件的例子,其中base-package表示为需要扫描的所有子包。
共同点:被@controller 、@service、@repository 、@component 注解的类,都会把这些类纳入进spring容器中进行管理
Spring中@Component的作用相关推荐
- Spring中@component的使用
Spring中@component的使用 @component是spring中的一个注解,它的作用就是实现bean的注入,在探究@component前先了解一下注解?何为注解?注解本质上就是一个类,开 ...
- Spring中@ Component,@ Service,@ Controller和@Repository之间的区别
在了解Spring框架中@Repository @Component , @Service @Controller , @Repository @Controller和@Repository批注之间的 ...
- Spring/Spring-Boot中@Component的作用
今天在写程序的时候研究了一个以前没有太多想过的注解(@Component),在网上查找资料并经过实践,记录一下. 1.@controller 控制器(注入服务) 用于标注控制层,相当于struts中的 ...
- Spring 中 @Component、@Service 等注解如何被解析?
点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源 | http://8rr.co/EjqL 前言 @ ...
- Spring中的Aware作用以及源码
文章目录 1.源码 2.Aware调用链 3.initializeBean 初始化Bean 在有些场景中我们需要感知到容器的存在,需要获取容器的工具类,这个时候需要使用Spring Aware提供的工 ...
- Spring中的@ Component,@ Repository和@Service批注有什么区别?
@Repository @Component , @Repository和@Service批注可以在Spring中互换使用吗,或者除了充当注解设备外,它们还提供任何特定功能吗? 换句话说,如果我有一个 ...
- Spring Ioc注解式开发中注解的作用
Spring Ioc注解式开发中注解的作用 目标:本章节注重于Spring Ioc的注解式开发之中注解的作用. 基于注解的DI实现IOC 1.定义bean而注解 a.@Component @Repos ...
- Spring中@AliasFor注解的作用及原理
本文基于Springboot 2.1.6.RELEASE 版本分析. 关于@AliasFor注解,曾提过的一个issue Explicit attribute overrides configured ...
- Spring中SmartLifecycle和Lifecycle的作用和区别
欢迎关注方志朋的博客,回复"666"获面试宝典 本文基于SpringBoot 2.5.0-M2讲解Spring中Lifecycle和SmartLifecycle的作用和区别,以及如 ...
最新文章
- 网络负载均衡相关技术-第四层交换功能
- 如何得到iterator的当前元素_Java中迭代器Iterator详解
- hibernate主键详细介绍
- buu Quoted-printable
- 个性化推荐系统该如何评估,四种不同策略的角度
- Android 图形驱动初始化
- 项目中的模块剥离成项目_使用MCEBuddy 2从电视录制中剥离广告
- java 键入_在Java中键入Safe SQL
- python+Android+uiautomator的环境
- Android 自定义带拼音Textview 带音调
- s一般怎么称呼自己的m_英文信的开头和结尾,怎么写才不会出错?
- 卫星定位领域相关基础知识汇总
- 用VB实现的QQ自动登录器
- 企鹅F4手机外观设计有突破 配MTK6592八核处理器
- 打卡day07 python基础—函数
- linux 虚拟ip 作用,linux-高可用之虚拟ip地址(VIP)
- 如何把苹果卖出高价?
- Android App接入支付功能——支付宝支付
- Spring Cloud Contract 初识之一 :简介
- 计算机音乐谱黑猫警长,求大神给乐谱音符@要黑猫警长 舒克贝塔和葫芦娃的