In my controller I have a ethod annotated by GetMapping and I want to validate the path variable. I tested the @max and @min. they were ok. but the thing is when I want to check when no path variable is not passed, I get 404 error code. meaning that i want to test the case like:
http://localhost:9090/api/mancala-game/last-state/
where there is nothing after the last /.
I want to get the exception in my ExceptionHandler class.
any ideas? thank you
CodePudding user response:
I think http://localhost:9090/api/mancala-game/last-state/
and
http://localhost:9090/api/mancala-game/last-state/{key}
is two api.
you can create /last-state
and /last-state/{key}
CodePudding user response:
You should send path variable , in the url it self otherwise you will throw 404 error . when your are not sending path variable it will be a different API: in your case : http://localhost:9090/api/mancala-game/last-state/ and this url is not pointing to any handling method in your controller, So you will get 404 error.
CodePudding user response:
What you want to do is add a wildcard **
at the end of the REST endpoint api/mancala-game/last-state/
at the place where you call the antMatchers()
method for this REST endpoint. For example:
.authorizeRequests().antMatchers(HttpMethod.GET, "api/mancala-game/last-state/**").permitAll() //Other antMatchers after this..