Component class
Marks a class as a bean: an object the container creates once, injects into others and closes at shutdown.
This is how most of an application's objects are declared. The
generator finds the annotated classes under a directory scanned by a
ComponentScan (or @SpringBootApplication), and the container calls
the constructor with the other beans it asks for. You never write
new for such a class or pass its dependencies by hand.
The bean name defaults to the class name in lowerCamelCase
(AuthService becomes authService; URLService stays as it is). An
explicit name must not be empty, blank or padded with spaces. Only
classes can be beans: on a mixin, enum, extension or extension type the
build fails. The scan skips abstract classes. Service, Repository
and Controller work the same way and only say what the class is for;
subclass Component to make your own such annotation.
@Component()
class Clock {
DateTime now() => DateTime.now();
}
// Named explicitly because another library looks it up by name; the
// container passes the Clock bean to the constructor.
@Component('auditLog')
class AuditLog {
AuditLog(this.clock);
final Clock clock;
}
Spring (Java):
@Component
class Clock { ... }
@Component("auditLog")
class AuditLog {
AuditLog(Clock clock) { ... }
}
Constructors
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited