Class BeanAnnotation

java.lang.Object
org.apache.juneau.commons.inject.BeanAnnotation

public class BeanAnnotation extends Object
Utility classes and methods for the @Bean annotation.
  • Field Details

    • DEFAULT

      public static final Bean DEFAULT
      Default value
  • Method Details

    • create

      public static BeanAnnotation.Builder create()
      Instantiates a new builder for this class.
      Returns:
      A new builder object.
    • name

      public static String name(Bean a)
      Pulls the name/value attribute from a Bean annotation.
      Parameters:
      a - The annotation to check. Can be null (returns an empty string).
      Returns:
      The annotation value, or an empty string if the annotation is null.
    • find

      public static Optional<Bean> find(MethodInfo method)
      Finds the @Bean annotation that applies to the specified method.

      The result is the method's own declared @Bean, or else the one declared on a method it truly overrides. A parent method only counts as overridden when it is non-private, non-static, not a bridge/synthetic method, and (when package-private) declared in the same package as the method. This is stricter than MethodInfo.getAnnotations(), which also merges annotations from same-signature private or static parent methods that are not overrides.

      Bridge and synthetic methods always return Optional.empty().

      Example:

      public class Parent { @Bean(name="db") public HealthIndicator dbIndicator() { ... } } public class Child extends Parent { @Override public HealthIndicator dbIndicator() { ... } // Not annotated, but overrides an annotated method. } MethodInfo mi = ClassInfo.of(Child.class).getDeclaredMethod(x -> x.hasName("dbIndicator")).get(); Optional<Bean> bean = BeanAnnotation.find(mi); // Present, name="db".

      Parameters:
      method - The method to inspect. Must not be null.
      Returns:
      The applicable annotation, or Optional.empty() if none applies.