Reputation: 1
I changed HTML files location and moved them to subdirectories in resource/templates
. The problem is after changing location, my @ControllerAdvice
class and @ExceptionHandler
stopped working with Thymeleaf (previously after catching exception, it was showing my custom message on thymeleaf view).
My subdirectiories in resource
Does anyone know what could be the cause of this? I have spent hours trying, but nothing seems to solve my problem. I added this in application properties, as after creating subdirectories, i got stuck in infinite loop and my view were not loading
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
Upvotes: 0
Views: 32
Reputation: 61
Update the View Names in Exception Handling: If your @ExceptionHandler is pointing to a view name like "errorPage", but the template is now in a subdirectory (e.g., resource/templates/error/errorPage.html), you need to update the view name in your exception handler to match the new path:
@ExceptionHandler(Exception.class)
public String handleSomeException() {
return "error/errorPage"; // updated path
}
Upvotes: 0