@Autowired vs @Inject vs @Resource — Three Injection Annotations
Fast recall
Quick revision
Core answer
@Qualifier. `@Inject` (JSR-330) is the standard Java DI annotation — same by-type resolution as @Autowired but with no required=false option (use Optional or Provider). `@Resource` (JSR-250 / Jakarta) injects by name first, then by type — the opposite of @Autowired. Use @Autowired for Spring-only projects, @Inject for portable code that might run on other DI containers, and @Resource only when you specifically want name-first resolution (typically for legacy Java EE code).Whether the candidate knows these three annotations exist, understands the type-vs-name resolution difference, and can explain when each is the right choice.
Saying they're identical, or not knowing that @Resource resolves by name first while @Autowired resolves by type first.
Mention that constructor injection is recommended over field injection for testability, that @Inject + Provider<T> is the JSR-330 equivalent of ObjectProvider, and that @Resource on the field name is what makes it ambiguity-friendly.
Interview-ready guide
Interview answer
All three annotations perform dependency injection, but they come from different specifications and resolve dependencies differently.
`@Autowired` — Spring-native
- Resolves by type first; falls back to bean name matching the field name
- Use
@Qualifier("name")to disambiguate when multiple beans of the same type exist - Supports
required = falsefor optional dependencies - Constructor injection is preferred — enables
finalfields and easier testing - Since Spring 4.3, optional on a single constructor — Spring auto-detects
`@Inject` — JSR-330 standard
- Same type-first resolution as
@Autowired - Portable: works on Spring, Guice, CDI, Dagger — any JSR-330 container
- Disambiguation via
@Named("name")instead of@Qualifier - No
requiredflag — useOptionalfor optional,Providerfor lazy/per-call - Best for shared library code or hexagonal architecture
`@Resource` — JSR-250 / Jakarta
- Resolves by name first, then by type — opposite of
@Autowired - Field/setter only — no constructor injection
- Useful for legacy Java EE code or when name-based DataSource selection is more readable than
@Qualifier - Field name matches bean name implicitly — convenient pattern
The decision rule
- Spring-only project:
@Autowired - Portable library code:
@Inject - Name-first resolution or Java EE migration:
@Resource
Most modern Spring codebases standardize on @Autowired with constructor injection — that's the idiomatic choice.
@Autowired vs @Inject vs @Resource — Three Injection Annotations
Direct Answer
All three perform dependency injection but come from different specifications and use different resolution strategies. @Autowired (Spring) injects by type by default; falls back to name with @Qualifier. @Inject (JSR-330) is the standard Java DI annotation — same by-type resolution as @Autowired but with no required=false option (use Optional<T> or Provider<T>). @Resource (JSR-250 / Jakarta) injects by name first, then by type — the opposite of @Autowired. Use @Autowired for Spring-only projects, @Inject for portable code that might run on other DI containers, and @Resource only when you specifically want name-first resolution (typically for legacy Java EE code).
Common Mistakes & Pitfalls
Saying they're identical, or not knowing that @Resource resolves by name first while @Autowired resolves by type first.
Check your understanding
Answer these without looking back at the article.
- Why is constructor injection preferred over field injection?
- What is the JSR-330 equivalent of Spring's @Qualifier?
- How would you inject an optional dependency with @Inject (no required flag)?
- When would you choose @Resource over @Autowired?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.