Annotation Interface Bean


@Target(METHOD) @Retention(RUNTIME) public @interface Bean
Marks a factory method in a Configuration class whose return value is registered as a singleton.

The bean is registered under the method's declared return type, so returning an interface makes the bean injectable by that interface. Method parameters are resolved like constructor parameters. The returned object gets field injection and PostConstruct unless it is already managed by the registry.

Each type can only be provided once: a second Bean for the same type, a Service class of that type, a Service that binds to it, or an instance registered under it are reported as errors. A bean takes precedence over automatic implementation discovery for interfaces and abstract classes.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether the bean is created on startup instead of when it is first needed.
    Default is false (lazy loading).
  • Element Details

    • eagerlyLoad

      boolean eagerlyLoad
      Whether the bean is created on startup instead of when it is first needed.
      Default is false (lazy loading).
      Default:
      false