Annotation 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
during component scanning. If the config value is false (or missing),
the component is skipped entirely.
根据 YAML 配置值条件性地注册组件。放在 @Service、@CmdExecutor、
@EventListener 或任何组件类上时,框架在组件扫描期间检查指定的配置文件和键。
如果配置值为 false(或缺失),则完全跳过该组件。
Usage example:
@CmdExecutor(alias = {"warp"}, permission = "ultikits.tools.command.warp")
@ConditionalOnConfig(value = "config/config.yml", path = "enableWarp")
public class WarpCommands extends AbstractCommandExecutor {
// Only registered if enableWarp: true in config.yml
}
- Since:
- 6.2.0
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIf true, register when the config value is false (inverted logic).
-
Element Details
-
value
String valueConfig file path relative to the plugin data folder.相对于插件数据目录的配置文件路径。
- Returns:
- the config file path
-
path
String pathDot-separated or slash-separated YAML key path.点分隔或斜杠分隔的 YAML 键路径。
- Returns:
- the config key path
-
negate
boolean negateIf true, register when the config value is false (inverted logic).如果为 true,则在配置值为 false 时注册(反转逻辑)。
- Returns:
- true to negate the condition
- Default:
false
-