DEV Community

MAYUR KUMBHAR
MAYUR KUMBHAR

Posted on • Updated on

Difference between @Autowiring ➿& @Inject πŸ”Œ

In article we looked at how wiring works in the spring framework, how to use the @Autowired annotation and different ways to use it.
Here we will briefly compare the @Autowired annotation with @Inject annotation.

Qualifier support

  • @Autowired built-in support the qualifier to qualify which exact bean to use foe dependency injection.
  • @Inject dose not have built-in support for qualifying the specific bean.

Standardization of annotation

  • @Autowired is annotation specific to spring framework and dose not work outside spring context
  • @Inject is part of java dependency injection (JSR-330).

Optional Dependency Support

  • @Autowired supports the optional dependency with Optional<T>
  • @Inject however dose not have built-in mechanism to make dependency as optional

Framework Integration

  • @Autowired is specifically developed to use with the spring framework.
  • @Inject is more general annotation can be used with any framework supporting the JSR-330

Note that both @Inject and @Autowired serve the purpose of dependency injection and can be used effectively in their respective contexts


Top comments (0)