@Named is the JSR-330 annotation jakarta.inject.Named. It does two jobs: on a class it gives a component a name, and on an injection point it selects which named bean to inject. Spring treats @Named on a class like @Component and @Named on a field or parameter like @Qualifier.
The annotation comes from the standard dependency injection API, so code that uses it is not tied to Spring. The same code can run on CDI containers, Guice and other JSR-330 implementations.
@Named was javax.inject.Named for years. Since Jakarta EE 9 the package is jakarta.inject, and Spring Framework 6 and Spring Boot 3 and later expect the Jakarta names.
| Framework generation | Import |
|---|---|
| Spring 5 / Spring Boot 2 | javax.inject.Named |
| Spring 6 and later / Spring Boot 3 and later | jakarta.inject.Named |
To use it, add the jakarta.inject:jakarta.inject-api dependency. Spring detects it on the classpath automatically.
Placed on a class, @Named registers it as a bean, just as @Component does. The optional value is the bean name; without it, Spring derives the name from the class name.
Classes must be found by component scanning, for example through @SpringBootApplication.
When several beans implement the same interface, injection by type is ambiguous. @Named on the injection point selects one by name:
Here @Inject replaces Spring's @Autowired, and @Named("emailNotifier") plays the role of @Qualifier("emailNotifier").
| Aspect | @Named | Spring annotations |
|---|---|---|
| Origin | JSR-330 standard | Spring specific |
| On a class | Same as @Component | @Component |
| On an injection point | Same as @Qualifier | @Qualifier |
| Scope | No built-in scope: singleton by default in Spring | @Scope or stereotype defaults |
| Required flag | Not available | @Autowired(required = false) |
| Custom stereotypes | Not meaningful | @Service, @Repository, @Controller add semantics |
Spring's stereotypes carry extra meaning: @Repository enables persistence exception translation and @Controller marks web handlers. @Named does not, so in a Spring application the stereotypes are usually the better fit for those layers.
@Named is itself a qualifier, and string names are easy to mistype. For frequently used choices, JSR-330 lets you define a typed qualifier with @Qualifier from jakarta.inject:
Annotate the bean with @Email and the injection point with @Email, and the compiler checks the spelling for you.
Use @Named when the code must stay portable across DI containers or when you are migrating a codebase from CDI or Guice. In a Spring-only project, @Component, @Service and @Qualifier are more expressive and are the common choice. Do not mix styles within one class without reason, because it confuses readers.
On a class, Spring handles it the same way: it registers a bean. It has no stereotype meaning beyond that.
Spring 6 moved to the Jakarta namespace. Replace javax.inject imports with jakarta.inject and use the Jakarta dependency.
@Qualifier is Spring's annotation, and jakarta.inject.Qualifier is the standard meta-annotation for defining qualifiers. @Named is a ready-made string qualifier built on the standard one.
Yes. Put @Named("beanName") on the constructor parameter, as in the example above.
@Named is the standard JSR-330 way to name a bean and to pick one by name. Spring supports it as an equivalent of @Component and @Qualifier. Use the jakarta.inject package on current Spring versions, and prefer typed qualifiers over raw strings when names repeat across the code.