This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.3.3!spring-doc.cn

Annotation

@Command annotation when used on a method marks it as a candidate for command registration. In below example a command example is defined.spring-doc.cn

class Example {

	@Command(command = "example")
	public String example() {
		return "Hello";
	}
}

@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.spring-doc.cn

@Command(command = "parent")
class Example {

	@Command(command = "example")
	public String example() {
		return "Hello";
	}
}

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.spring-doc.cn

You can define target classes using @EnableCommand. It will get picked from all Configuration classes.spring-doc.cn

@EnableCommand(Example.class)
class App {
}

You can define target classes using @CommandScan. It will get picked from all Configuration classes.spring-doc.cn

Define @CommandScan in Spring Boot App class on a top level and it will automatically scan all command targets from all packages and classes under App.
@CommandScan
class App {
}