验证

Spring Shell 集成了 Bean Validation API,以支持对命令参数的自动和自文档化约束。

命令参数上的注解和方法级的注解都会被识别并在命令执行前触发验证。考虑以下命令

	@ShellMethod("Change password.")
	public String changePassword(@Size(min = 8, max = 40) String password) {
		return "Password successfully set to " + password;
	}

从上面的例子中,你可以免费获得以下行为

shell:>change-password hello
The following constraints were not met:
	--password string : size must be between 8 and 40 (You passed 'hello')