I want to return a custom 404 error using SpringBoot, but I would like to add some server logic to it, and not just a static page.
1. I disabled the default whitelabel page in application.properties
error.whitelabel.enabled=false
2. I added Thymeleaf error.html to resources/templates
It works, by the way. The page is served, but the controller is not called.
3. I created the Error class as a โControllerโ
package com.noxgroup.nitro.pages; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/error") public class Error { @ExceptionHandler public String index() { System.out.println("Returning Error"); return "index"; } }
Unfortunately, I do not see Returning Error anywhere in the console.
I am using Embedded Tomcat with Spring Boot. I saw various options that do not work, including using @ControllerAdvice, removing RequestMapping, etc. Doesnโt work for me.
source share