该接口定义了命令注册在 shell 应用程序。可以动态注册和取消注册 命令,在可能的情况下为用例提供灵活性 来来去去,取决于 shell 的状态。请看以下示例:CommandCatalogSpring中文文档

CommandRegistration registration = CommandRegistration.builder().build();
catalog.register(registration);

命令解析程序

您可以实现接口并定义一个 Bean 来动态地 解析从命令名称到其实例的映射。考虑 以下示例:CommandResolverCommandRegistrationSpring中文文档

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;
	}
}
a 的当前限制是每次解析命令时都使用它。 因此,如果命令解析调用需要很长时间,我们建议不要使用它,因为它会 使外壳感觉迟钝。CommandResolver
a 的当前限制是每次解析命令时都使用它。 因此,如果命令解析调用需要很长时间,我们建议不要使用它,因为它会 使外壳感觉迟钝。CommandResolver

命令目录定制器

您可以使用该界面自定义 . 它的主要用途是修改目录。此外,在自动配置中,这 接口用于将现有 Bean 注册到目录中。 请看以下示例:CommandCatalogCustomizerCommandCatalogspring-shellCommandRegistrationSpring中文文档

static class CustomCommandCatalogCustomizer implements CommandCatalogCustomizer {

	@Override
	public void customize(CommandCatalog commandCatalog) {
		CommandRegistration registration = CommandRegistration.builder()
			.command("resolve command")
			.build();
		commandCatalog.register(registration);
	}
}

您可以创建一个 bean,其余的由 Spring Shell 处理。CommandCatalogCustomizerSpring中文文档