Annotation Type Bean


@Target(METHOD) @Retention(SOURCE) public @interface Bean
Marks methods on a @Factory bean that create dependencies.

See Factory.


@Factory
class Configuration {

  private final StartConfig startConfig;

  @Inject
  Configuration(StartConfig startConfig) {
    this.startConfig = startConfig;
  }

  @Bean
  Foo buildFoo() {
    ...
    return new Foo(...);
  }

  @Bean
  Bar buildBar(Foo foo, Bazz bazz) {
    ...
    return new Bar(...);
  }
}
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Specify that the concrete instance of the bean is an AutoCloseable.
    Specify a method to be treated like a @PreDestroy
    int
    Specify the priority of the destroy method to control its execution order relative to other destroy methods.
    Specify a method to be treated like a @PostConstruct
  • Element Details

    • initMethod

      Specify a method to be treated like a @PostConstruct
      Default:
      ""
    • destroyMethod

      Specify a method to be treated like a @PreDestroy
      Default:
      ""
    • destroyPriority

      Specify the priority of the destroy method to control its execution order relative to other destroy methods.

      Low values execute earlier than high values.

      Default:
      1000
    • autoCloseable

      boolean autoCloseable
      Specify that the concrete instance of the bean is an AutoCloseable. Use if the bean interface doesn't extend AutoCloseable but the concrete class implements it.
      Default:
      false