The difference between @Inject and @Autowire vs. @Resource?
@Autowired: spring likelihood annotations (as opposed to @Inject and @Resource) that introduce a resource by type, i.e. by interface class of the annotated field or contractor interface. If we have little implementation of the interface or subclass, we can narrow the selection using annotation @Qualifier to avoid ambiguity. For reciprocal matching, the bean name is considered the default qualifier value. Although you can use this convention to refer to specific beans by name, @Autowired is mainly related to input with type with additional semantic classifiers.
@Inject: JSR-330 (Dependency Injection for Java) annotations identify constructors, methods, and injection fields. This annotation is almost a complete replacement replacement for Spring s @ Automatic annotation. Thus, instead of using Spring-specific @Autowired annotations, you can use @Inject. One of the differences between @Autowired and @Inject is that @Inject does not have the required field, so if we fail to find a suitable input object, it will fail, and @Autowired may use required = false and allow the field with zero value (only if necessary!). The advantage of the @Inject annotation is that instead of entering the link directly, you can ask @Inject to enter the provider. The provider interface includes, among other things, lazy injection of bean links and insertion of multiple instances of bean. If we have few implementations of an interface or subclass, we can narrow down our choices using the @Named annotation to avoid ambiguity. @Named annotation works just like Spring s @Qualifier
@Resource: annotation based on JSR-250. @Resource is very similar to @Autowired and @Inject, but the main difference is the execution paths needed to find the required bean for input. @Resource narrows the search first by name, then by type and, finally, by Qualifications (ignored if a match is found by name). @Autowired and @Inject narrow down the search first by type, then by qualifier, and finally by name.
Haim Raman Dec 08 '13 at 9:42
source share