当前位置:网站首页>@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
边栏推荐
猜你喜欢

(五)R语言入门生物信息学——ORF和序列分析

Analysis of charging architecture of glory magic 3pro

C语言回调函数【C语言】

E-commerce data analysis -- salary prediction (linear regression)

Redis based distributed locks and ultra detailed improvement ideas

JS object and event learning notes
![[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree](/img/6e/0802a92511ac50a652afa1678ad28c.jpg)
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree

【ESP32学习-1】Arduino ESP32开发环境搭建
![[esp32 learning-2] esp32 address mapping](/img/ee/c4aa0f7aed7543bb6807d7fd852c88.png)
[esp32 learning-2] esp32 address mapping

Cannot change version of project facet Dynamic Web Module to 2.3.
随机推荐
Togglebutton realizes the effect of switching lights
.elf .map .list .hex文件
2022.2.12 resumption
JS正则表达式基础知识学习
RT thread API reference manual
ARM PC=PC+8 最便于理解的阐述
Arm pc=pc+8 is the most understandable explanation
Gallery's image browsing and component learning
Kconfig Kbuild
嵌入式启动流程
Detailed explanation of 5g working principle (explanation & illustration)
Mysqldump error1066 error solution
Arduino gets the length of the array
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
MySQL占用内存过大解决方案
ESP learning problem record
Cannot change version of project facet Dynamic Web Module to 2.3.
[esp32 learning-2] esp32 address mapping
Types de variables JS et transformations de type communes