Annotation Interface Bean


@Target(METHOD) @Retention(RUNTIME) public @interface Bean
Bean annotation to replace Spring's @Bean.

name() and value() are mutual aliases (D-06): declaring both with different content is a malformed declaration and fails the module's load, naming the declaring method and both declared values; declaring both with identical content is legal. An empty or absent name()/value() falls back to the factory method's own name, exactly as before this attribute took effect. When more than one name is declared, the first element is the bean's registered name and the rest are aliases sharing the same fully-assembled instance -- Spring's own @Bean convention. A declared element that is blank or whitespace-only also fails the module's load, naming the offending method: a name that cannot name anything is not a usable third state between "declared" and "absent".

@Target declares ElementType.METHOD only. It used to also permit placing this annotation on an annotation type declaration, but no code path in this framework ever acted on a @Bean placed there -- ComponentScanner.processBeanMethod and SimpleContainer.processConfigurationClass both only ever look for @Bean on methods -- so the wider target let an author place this annotation somewhere nothing would ever read it. Narrowed to methods only in 6.3.0 (issue #348); no semantics for the removed target were implemented, since nothing has ever acted on it and inventing a meaning for it here would be a new declared surface with no consumer.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Bean name.
    Bean value (alias for name).
  • Element Details

    • name

      String[] name
      Bean name.
      Returns:
      bean name
      Default:
      {}
    • value

      String[] value
      Bean value (alias for name).
      Returns:
      bean value
      Default:
      {}