Inject and Resource and Autowired annotations

Viewed 39746

What's the difference between @Inject and @Resource and @Autowired annotations?

When should we use each of them?

3 Answers
|------------|---------------|---------------|---------------|-----------------------|
|            | Setter/Field  | Constructor   | Applicable to | Matching order        |
|            | injection     | injection     | type          |                       |
|------------|---------------|---------------|---------------|-----------------------|
| @Autowired |       X       |       X       |               | Type, Qualifier, Name |
|------------|---------------|---------------|---------------|-----------------------|
| @Inject    |       X       |       X       |               | Type, Qualifier, Name |
|------------|---------------|---------------|---------------|-----------------------|
| @Resource  |       X       |               |       X       | Name, Type, Qualifier |
|------------|---------------|---------------|---------------|-----------------------|

So in Spring dependency injection @Inject and @Autowired have exactly the same behaviour.

Related