Annotation Type Autowired
Asks the build to inject this constructor, field or setter.
A class with exactly one public constructor does not need the annotation on it -- that constructor is used -- which is Spring's rule too. A field or a setter does: the build injects members only when asked.
A private field is fine. The build adds a setter to the compiled class for the generated entry point to call, because there is no reflection to reach it with. A final field cannot be injected at all, and is refused.
-
Optional Element Summary
Optional Elements
-
Element Details
-
required
boolean requiredWhether a bean must exist. When false and there is none, the field keeps its initial value, the setter is not called, and a constructor parameter receives null.- Default:
true
-