0

I've been looking and with can't seem to find how to set a page for 404 errors. I can set them for errors that I throw. Like if I have baseurl/product/{key} and the key is invalid I can throw that to a 404 but the user just enters a wrong url like baseurl/produckt/{key} (note the misspelling) I can't seem to figure out how to catch that. I am using JavaConfig, not a web.xml.

I've tried something like

@PreAuthorize("permitAll()")
@GetMapping("/**")
public String error404(){
    return "error404";
}

And that 'works' for detecting urls I don't have mapped, but it also makes other things behave wrong.

Issam El-atif
  • 2,366
  • 2
  • 17
  • 22
John
  • 1,808
  • 7
  • 28
  • 57
  • 1
    Are you using Spring Boot? Boot has added some built-in error controllers that you can use. If so, add the [tag:spring-boot] tag and at me and I'll undo the dupe, since the dupe is for pre-Boot Spring. – chrylis -cautiouslyoptimistic- Nov 08 '16 at 15:00
  • @chrylis No I'm not using spring boot on this particular project. The spring-boot built in stuff is what lead me to add this though! The dupe tag pointed me in the right direction and I was able to get it working. Thank you – John Nov 08 '16 at 15:16

0 Answers0