Annotation Interface Bean


@Retention(RUNTIME) @Target(METHOD) public @interface Bean
Annotation indicating that a method will be used to create Singleton or Prototype Beans. The result of the method invocation is an object that represents a Bean that can be injected into other Beans via constructor, field injection or setter using Autowired annotation.

This annotation should be used only for methods under a configuration class (a class annotated with @Configuration). When applied to a method, it becomes eligible for Bean definition registration and later used for Bean creation.

The name of the Bean will be the name of the method. Injection of other Bean via parameter is possible by adding a method parameter of the type and name of a bean already defined in the Configuration class.

Usage Example:


 @Configuration
 public class MyConfiguration {

     @Bean
     public String stringBean1() {
         return "Hello, 1";
     }

     @Bean
     public String stringBean2(String stringBean1) {
         return stringBean1 + "!";
     }
 }
 
Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the Bring bean.
  • Element Details

    • value

      String value
      The name of the Bring bean. If not specified, the bean name will be generated based on the method name.
      Returns:
      the name of the Bring bean
      Default:
      ""