当前位置:网站首页>@The difference between Autowired and @resource
@The difference between Autowired and @resource
2022-07-06 12:17:00 【A pole】
@Autowired and @Resource The difference between
Different default injection methods
@Autowired The default injection method is byType( Match by type ), In other words, it will give priority to matching and injecting according to the interface type Bean ( Implementation class of interface ), If you want to specify a name , Can pass @Qualifier In combination with .
@Autowired
private UserSafetyMapper userSafetyMapper;
// or
@Autowired @Qualifier("userSafetyMapper")
private UserSafetyMapper userSafetyMapper;
@Resource The default injection method is byName( Match according to the name ). If you cannot match the corresponding implementation class by name , The injection method will change to byType.
- If you also specify name and type, From Spring Unique match found in context bean Assembly , Throw exception if not found ;
- If you specify name, Find name from context (id) Matching bean Assembly , Throw exception if not found ;
- If you specify type, Then find the unique type match from the context bean Assembly , Can't find or find more than one , Will throw an exception ;
- If neither name, It's not specified type, Then automatically follow the byName Method of assembly ; If there is no match , Back off to match as an original type , Auto assemble if match .
// 1. Default injection mode
@Resource
private UserSafetyMapper userSafetyMapper;
// 2. Specify the injection method
@Resource(name = "userSafetyMapper", type = UserSafetyMapper.class)
private UserSafetyMapper userSafetyMapper;
Different providers
@Autowired yes spring Notes provided ,@Resource yes JDK Notes provided
边栏推荐
- Arm pc=pc+8 is the most understandable explanation
- . elf . map . list . Hex file
- OSPF message details - LSA overview
- arduino获取随机数
- Who says that PT online schema change does not lock the table, or deadlock
- Gallery's image browsing and component learning
- Redis based distributed ID generator
- Raspberry pie tap switch button to use
- RT-Thread 线程的时间片轮询调度
- Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
猜你喜欢

荣耀Magic 3Pro 充电架构分析

Priority inversion and deadlock

Programmers can make mistakes. Basic pointers and arrays of C language

【ESP32学习-2】esp32地址映射

js 变量作用域和函数的学习笔记

STM32 how to locate the code segment that causes hard fault

JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.

Reno7 60W超级闪充充电架构

Togglebutton realizes the effect of switching lights

MySQL占用内存过大解决方案
随机推荐
JS function promotion and declaration promotion of VaR variable
AMBA、AHB、APB、AXI的理解
Navigator object (determine browser type)
ES6语法总结--下篇(进阶篇 ES6~ES11)
程序员老鸟都会搞错的问题 C语言基础 指针和数组
Pytorch: tensor operation (I) contiguous
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Pytoch temperature prediction
[esp32 learning-1] construction of Arduino esp32 development environment
Selective sorting and bubble sorting [C language]
RT-Thread 线程的时间片轮询调度
Basic operations of databases and tables ----- modifying data tables
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
JS變量類型以及常用類型轉換
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Pytorch four commonly used optimizer tests
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
ES6语法总结--上篇(基础篇)
Time slice polling scheduling of RT thread threads
[esp32 learning-2] esp32 address mapping