Annotation Interface ConditionalOnConfig


@Target(TYPE) @Retention(RUNTIME) public @interface ConditionalOnConfig
Conditionally registers a component based on a YAML config value.

When placed on a @Service, @CmdExecutor, @EventListener, or any component class, the framework checks the specified config file and key once, during component scanning at plugin startup. Only a boolean true counts as true: any other value, a missing key or file, or a file that cannot be read or parsed counts as false. A false result skips the component unless negate = true, which reverses the decision. If the file holds the path in more than one form, the framework refuses to load the module.

Usage example:

@CmdExecutor(alias = {"warp"}, permission = "ultikits.tools.command.warp")
@ConditionalOnConfig(value = "config/config.yml", path = "enableWarp")
public class WarpCommands extends BaseCommandExecutor {
    // Only registered if enableWarp: true in config.yml
}

A restart is required for a change to the named key to take effect, in both directions. ul reload re-reads the config file, but only reports the drift as a Level.WARNING naming the class, the file, the key, and the new direction -- it does not register or unregister anything (issue #392, D-01). See com.ultikits.ultitools.context.ConditionalRegistrationEvaluator for the reporting mechanism and why re-registering on reload was rejected.

This is not equivalent to an in-code if (config.isEnabled()) block, which re-reads the config value on every call and therefore does follow a reload. A module author migrating off a hand-written if block onto this annotation is trading that per-call freshness for load-time simplicity -- know that before switching.

Since:
6.2.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The setting's dotted path, resolved as for ConfigEntry.path(): it can be written as nested keys, one flat dotted key, or a mix.
    Config file path relative to the module's configuration folder (plugins/UltiTools/pluginConfig/<module name>/, given by UltiToolsPlugin#getResourceFolderPath()), for example config/config.yml.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    If true, register when the config value is false (inverted logic).
  • Element Details

    • value

      String value
      Config file path relative to the module's configuration folder (plugins/UltiTools/pluginConfig/<module name>/, given by UltiToolsPlugin#getResourceFolderPath()), for example config/config.yml.
      Returns:
      the config file path
    • path

      String path
      The setting's dotted path, resolved as for ConfigEntry.path(): it can be written as nested keys, one flat dotted key, or a mix. A slash is part of a key, not a separator.
      Returns:
      the config key path
    • negate

      boolean negate
      If true, register when the config value is false (inverted logic).
      Returns:
      true to negate the condition
      Default:
      false