Annotation Interface Named


Identifies a bean injection qualifier for constructor/method parameters.

This annotation is used to specify which named bean should be injected into a constructor or method parameter. It serves the same purpose as the standard javax.inject.Named annotation but without requiring a dependency on the javax.inject module.

Example:

public MyClass(@Named("myBean") MyBean bean) { // Constructor will receive the bean named "myBean" from the BeanStore }

Comparison with @Name:

Do not confuse this annotation with @Name, which serves a different purpose:

  • @Named - Specifies which named bean to inject (bean qualifier)
  • @Name - Specifies the parameter name for bean property mapping when bytecode parameter names are not available
Example showing the difference:

// @Named - for bean injection public MyService(@Named("primaryDb") Database db) { // Injects the bean named "primaryDb" from BeanStore } // @Name - for parameter naming (when bytecode names unavailable) public Person(@Name("firstName") String arg0, @Name("lastName") String arg1) { // Maps constructor parameters to bean properties "firstName" and "lastName" // Useful when class is not compiled with -parameters flag }

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The bean name to use for injection.
  • Element Details

    • value

      The bean name to use for injection.
      Returns:
      The bean name.