Programmatic

在编程模型中,CommandRegistration 可以定义为 @Bean,它将自动注册。

Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]

如果你的所有命令有一些共同点,那么将创建 CommandRegistration.BuilderSupplier 的一个实例,它可以进行自动装配。此供应商的默认实现返回一个新的构建器,因此你不必担心它的内部状态。

通过编程注册的命令会自动添加在 Help Options 中提到的 help options

如果定义了此供应商类型的 bean,那么自动配置将退出,让你有机会重新定义默认功能。

Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]

如果你想在上面提到的供应商给你的构建器实例上进行集中修改,那么可以定义 CommandRegistrationCustomizer bean。

Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]