驗證
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 : size must be between 8 and 40 (You passed 'hello')