fxleyu / precious-deposits

This repository is used for shell、Git、and etc. The taotie(饕餮) likes to eat and drink.
1 stars 0 forks source link

Spring 注入注解:@Autowired, @Resource and @Inject #298

Open fxleyu opened 4 years ago

fxleyu commented 4 years ago

背景 做简单防腐层时,发现使用 @Resource 注解导致类型不匹配,最后发现如下内容

The @Resource Annotation

The @Resource annotation is part of the JSR-250 annotation collection and is packaged with Jakarta EE. This annotation has the following execution paths, listed by precedence:

These execution paths are applicable to both setter and field injection.

The @Inject Annotation

The @Inject annotation belongs to the JSR-330 annotations collection. This annotation has the following execution paths, listed by precedence:

The @Autowired Annotation

The behaviour of @Autowired annotation is similar to the @Inject annotation. The only difference is that the @Autowired annotation is part of the Spring framework. This annotation has the same execution paths as the @Inject annotation, listed in order of precedence:

Match by Type Match by Qualifier Match by Name These execution paths are applicable to both setter and field injection.

来源: https://www.baeldung.com/spring-annotations-resource-inject-autowire