Annotation Interface ConfigBean


@Documented @Retention(RUNTIME) @Target(TYPE) @BuilderTrigger public @interface ConfigBean
A ConfigBean is another BuilderTrigger that extends the Builder concept to support the integration to Helidon's configuration sub-system. It basically provides everything that Builder provides. However, unlike the base Builder generated classes that can handle any object type, the types used within your target ConfigBean-annotated interface must have all of its attribute getter method types resolvable by Helidon's configuration sub-system.

The @code ConfigBean} is therefore a logical grouping for the "pure configuration" set of attributes (and sub-ConfigBean attributes) that typically originate from an external media store (e.g., property files, config maps, etc.), and are integrated via Helidon's Config subsystem at runtime.

One should write a ConfigBean-annotated interface in such a way as to group the collection of configurable elements that logically belong together to then be delivered (and perhaps drive an activation of) one or more java service types that are said to be ConfiguredBy the given ConfigBean instance.

The builder-config-processor module is required to be on the APT classpath to code-generate the implementation classes for the ConfigBean.

Example:


 @ConfigBean
 public interface MyConfigBean {
     String getName();
     int getPort();
 }
 

When Pico services are incorporated into the application lifecycle at runtime, the configuration sub-system is scanned at startup and ConfigBean instances are created and fed into the ConfigBeanRegistry. This mapping occurs based upon the ConfiguredOption.key() on each of the ConfigBean's attributes. If no such ConfiguredOption is found then the type name is used as the key (e.g., MyConfigBean would map to "my-config-bean").

Also see ConfiguredBy in Pico's config-driven module.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Represents the level in the config tree to search for config bean instances.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    An instance of this bean will be created if there are no instances discovered by the configuration provider(s) post startup, and will use all default values annotated using ConfiguredOptions from the bean interface methods.
    boolean
    Determines whether an instance of this config bean in the bean registry will result in the backing service ConfiguredBy this bean to be activated.
    The ConfigBean.LevelType of this config bean.
    boolean
    Determines whether there can be more than one bean instance of this type.
    The overridden key to use.
    boolean
    An instance of this bean will be created if there are no instances discovered by the configuration provider(s) post startup, and will use all default values annotated on the bean interface.
  • Element Details

    • value

      String value
      The overridden key to use. If not set this will default to use the expanded name from the config subsystem, (e.g. MyConfig -> "my-config").
      Returns:
      the overriding key to use
      Default:
      ""
    • drivesActivation

      boolean drivesActivation
      Determines whether an instance of this config bean in the bean registry will result in the backing service ConfiguredBy this bean to be activated.

      As of the current release, only ConfigBean.LevelType.ROOT level config beans can drive activation.

      The default value is false.

      Returns:
      true if this config bean should drive ConfiguredBy service activation
      Default:
      false
    • atLeastOne

      boolean atLeastOne
      An instance of this bean will be created if there are no instances discovered by the configuration provider(s) post startup, and will use all default values annotated using ConfiguredOptions from the bean interface methods.

      The default value is false.

      Returns:
      the default config bean instance using defaults
      Default:
      false
    • repeatable

      boolean repeatable
      Determines whether there can be more than one bean instance of this type.

      If false then only 0..1 behavior will be permissible for active beans in the config registry. If true then > 1 instances will be permitted.

      Note: this attribute is dynamic in nature, and therefore cannot be validated at compile time. All violations found to this policy will be observed during PicoServices activation.

      The default value is true.

      Returns:
      true if repeatable
      Default:
      true
    • wantDefaultConfigBean

      boolean wantDefaultConfigBean
      An instance of this bean will be created if there are no instances discovered by the configuration provider(s) post startup, and will use all default values annotated on the bean interface.

      As of the current release, only ConfigBean.LevelType.ROOT level config beans can be defaulted.

      The default value is false.

      Returns:
      use the default config instance
      Default:
      false
    • levelType

      The ConfigBean.LevelType of this config bean.

      The default level type is ConfigBean.LevelType.ROOT.

      Returns:
      the level type of this config bean
      Default:
      ROOT