Detailed explanation of @Resource

The role of @Resource is equivalent to @Autowired,

It's just that @Autowired is automatically injected by byType,
while @Resource is automatically injected by byName by default

@Resource has two important attributes, namely name and type. Spring resolves the name attribute of the @Resource annotation into the name of the bean, and the type attribute resolves to the type of the bean. So if you use the name attribute, use the automatic injection strategy of byName, and use the byType automatic injection strategy when using the type attribute. If neither the name nor the type attribute is specified, the byName automatic injection strategy will be used through the reflection mechanism.

@Resource(name="baseDao")
private BaseDao baseDao;



 

Guess you like

Origin blog.csdn.net/qq_42514371/article/details/126140420