命令目录
这指挥目录接口定义了命令注册在
一个壳体应用。可以动态注册和取消注册
这为可能的命令提供了灵活性,适用于
来来去去,取决于弹壳的状态。请考虑以下例子:
CommandRegistration registration = CommandRegistration.builder().build();
catalog.register(registration);
命令解析器
你可以实现指令解析器并动态地定义了 bean 与
解析命令名称到其指挥注册实例。考虑
以下示例:
static class CustomCommandResolver implements CommandResolver {
List<CommandRegistration> registrations = new ArrayList<>();
CustomCommandResolver() {
CommandRegistration resolved = CommandRegistration.builder()
.command("resolve command")
.build();
registrations.add(resolved);
}
@Override
public List<CommandRegistration> resolve() {
return registrations;
}
}
一个电流限制指令解析器而是每次命令解析时都会使用它。
因此,如果命令解析调用耗时较长,我们建议不要使用它,因为这确实如此
让壳体感觉迟钝。 |
命令目录定制器
你可以使用命令目录定制器用于自定义的接口指挥目录.
它的主要用途是修改目录。还有,在Spring Shell自动配置,这个
接口用于注册现有的指挥注册豆子被编成目录。
请考虑以下例子:
static class CustomCommandCatalogCustomizer implements CommandCatalogCustomizer {
@Override
public void customize(CommandCatalog commandCatalog) {
CommandRegistration registration = CommandRegistration.builder()
.command("resolve command")
.build();
commandCatalog.register(registration);
}
}
你可以创建一个命令目录定制器作为豆子,剩下的由春壳负责。