Annotation
当 @Command
注解被用于某个方法时,它将该方法标记为命令注册的候选方法。在下例中,命令 example
被定义。
@Command
annotation when used on a method marks it as a candidate for command registration.
In below example a command example
is defined.
Unresolved include directive in modules/ROOT/pages/commands/registration/annotation.adoc - include::../../test/java/org/springframework/shell/docs/CommandAnnotationSnippets.java[]
@Command
注解可以被放置在一个类上,该类定义了在同一个类中定义的 @Command
方法的默认设置或共享设置。在下例中,命令 parent example
被定义。
@Command
annotation can be placed on a class which either defines defaults or shared settings
for @Command
methods defined in a same class. In below example a command parent example
is
defined.
Unresolved include directive in modules/ROOT/pages/commands/registration/annotation.adoc - include::../../test/java/org/springframework/shell/docs/CommandAnnotationSnippets.java[]
使用 @Command
不会自动注册命令目标,而是需要使用 @EnableCommand
和/或 @CommandScan
注解。此模型与 Spring 伞形组织的其他部分的模型类似,并且为用户提供了更好的灵活性,对命令目标而言是包容性的,而不是排他性的。
Using a @Command
will not automatically register command targets, instead it is required to use
@EnableCommand
and/or @CommandScan
annotations. This model is familiar from other parts
of Spring umbrella and provides better flexibility for a user being inclusive rather than exclusive
for command targets.
你可以使用 @EnableCommand
来定义目标类。它可以从所有 Configuration 类中提取。
You can define target classes using @EnableCommand
. It will get picked from all Configuration
classes.
Unresolved include directive in modules/ROOT/pages/commands/registration/annotation.adoc - include::../../test/java/org/springframework/shell/docs/CommandAnnotationSnippets.java[]
你可以使用 @CommandScan
来定义目标类。它可以从所有 Configuration 类中提取。
You can define target classes using @CommandScan
. It will get picked from all Configuration
classes.
在顶层 on |
Define |
Unresolved include directive in modules/ROOT/pages/commands/registration/annotation.adoc - include::../../test/java/org/springframework/shell/docs/CommandAnnotationSnippets.java[]