当前位置:网站首页>@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
边栏推荐
- Pytoch implements simple linear regression demo
- Basic operations of databases and tables ----- creating data tables
- Several declarations about pointers [C language]
- Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
- 【ESP32学习-1】Arduino ESP32开发环境搭建
- Togglebutton realizes the effect of switching lights
- JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
- Mysqldump error1066 error solution
- JS regular expression basic knowledge learning
- Kconfig Kbuild
猜你喜欢
I2C总线时序详解
Basic operations of databases and tables ----- view data tables
level16
Time slice polling scheduling of RT thread threads
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
uCOS-III 的特点、任务状态、启动
Walk into WPF's drawing Bing Dwen Dwen
JS object and event learning notes
Working principle of genius telephone watch Z3
Characteristics, task status and startup of UCOS III
随机推荐
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
Keyword inline (inline function) usage analysis [C language]
ESP learning problem record
JS变量类型以及常用类型转换
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Characteristics, task status and startup of UCOS III
Cannot change version of project facet Dynamic Web Module to 2.3.
OPPO VOOC快充电路和协议
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
inline详细讲解【C语言】
Gallery's image browsing and component learning
Mysql database interview questions
CUDA C programming authoritative guide Grossman Chapter 4 global memory
The first simple case of GNN: Cora classification
Whistle+switchyomega configure web proxy
Common DOS commands
MySQL時間、時區、自動填充0的問題
[esp32 learning-2] esp32 address mapping
ESP8266使用arduino连接阿里云物联网
Oppo vooc fast charging circuit and protocol