驗證

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