驗證
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')