Named class
Explicitly specifies a name for a Pod (Dependency Injection component) that overrides all other naming mechanisms in the Jetleaf framework.
This annotation provides the highest precedence for Pod naming and can be applied to both classes and methods to explicitly define how they should be registered and referenced in the application context.
Naming Precedence Hierarchy
When multiple naming mechanisms are available, @Named takes precedence in this order:
- @Named (highest precedence - explicit override)
- @Component.name and related stereotype annotations
- @Pod.name for configuration methods
Usage Scenarios
- Explicit Pod Identification: When you need specific, predictable Pod names
- Disambiguation: When multiple Pods of the same type exist and need distinct names
- Configuration Override: When you want to override default naming conventions
- Integration: When integrating with systems that require specific Pod identifiers
Target Support
This annotation can be applied to:
- Classes: To name the Pod created from the class instance
- Methods: To name the Pod returned by a configuration method
Example
// Class-level usage - names the UserService Pod as 'userService'
@Named('userService')
@Service()
class UserService {
// Implementation...
}
// Method-level usage - names the DataSource Pod as 'primaryDataSource'
@Configuration()
class DataSourceConfig {
@Named('primaryDataSource')
@Pod()
DataSource createDataSource() {
return DataSource();
}
}
Framework Behavior
- Registration: Pods annotated with
@Namedare registered with the specified name - Lookup: Dependency injection uses the explicit name for resolution
- Validation: Duplicate Pod names will cause application startup failures
- Reflection: The name is available via reflection for framework components
Best Practices
- Use descriptive, meaningful names that indicate the Pod's purpose
- Follow consistent naming conventions across your application
- Consider using constants for Pod names to avoid typos
- Document why explicit naming is needed when used
Related Annotations
@Pod- Declares a method as producing a Pod@Service- Stereotype annotation for service layer Pods@Repository- Stereotype annotation for data access layer Pods@Component- Generic stereotype annotation for any Pod
- Annotations
-
- @Target.new({TargetKind.classType, TargetKind.method})
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The explicit name to use for this Pod in the application context.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited