Programmatic
在编程模型中,CommandRegistration
可以定义为 @Bean
,它将自动注册。
In the programmatic model, CommandRegistration
can be defined as a @Bean
and it will be automatically registered.
Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]
如果你的所有命令有一些共同点,那么将创建 CommandRegistration.BuilderSupplier 的一个实例,它可以进行自动装配。此供应商的默认实现返回一个新的构建器,因此你不必担心它的内部状态。
If all your commands have something in common, an instance of a CommandRegistration.BuilderSupplier is created which can be autowired. Default implementation of this supplier returns a new builder so you don’t need to worry about its internal state.
通过编程注册的命令会自动添加在 Help Options 中提到的 help options。
Commands registered programmatically automatically add help options mentioned in Help Options.
如果定义了此供应商类型的 bean,那么自动配置将退出,让你有机会重新定义默认功能。
If bean of this supplier type is defined then auto-configuration will back off giving you an option to redefine default functionality.
Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]
如果你想在上面提到的供应商给你的构建器实例上进行集中修改,那么可以定义 CommandRegistrationCustomizer
bean。
CommandRegistrationCustomizer
beans can be defined if you want to centrally
modify builder instance given you by supplier mentioned above.
Unresolved include directive in modules/ROOT/pages/commands/registration/programmatic.adoc - include::../../test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java[]