What is difference between these 2 injections ?
@Autowired
private DocumentDAO documentDao;
@Resource(name = "documentDao")
private DocumentDAO documentDao;
Simply, @Autowired(specification in Spring) wires by type and @Resource(specification in JSR-250) wires by name .
But, @Autowired with @Qualifier also can autowire by name as @Resource.
Please take a look below links:
@Autowire
@Resource
@Spring Injection with @Resource, @Autowired and @Inject
By default @Autowire
inject dependency "by Type". But It can also Inject dependency "by Name" using @Qualifier
in conjunction with @Autowire
annotation.
But the key difference is that @Autowired
is a spring annotation whereas @Resource
is specified by the JSR-250. So the @Resource
is part of normal Java on the other side, @Autowired
is only available by Spring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With