-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
error template resolution Spring Boot #304
Comments
@casid just wondering if you had time to have a look at this to give me feedback? @tschuehly perhaps you could have a look as well as I know you have a lot of experience using JTE and Spring Boot together and I think Casid doesn't use Spring Boot that much? |
Hey @maxwellt, Without looking further into it I would say we need to register a bean of type TemplateAvailabilityProvider in the JteAutoConfiguration of the spring boot starter. |
@maxwellt sorry for the late reply! I don't use Spring Boot, so I'm unfortunately not able to give any meaningful recommendations here. |
As a workaround register a custom ErrorViewResolver. @Bean
public ErrorViewResolver customErrorViewResolver() {
return (request, status, model) -> {
if (status.is4xxClientError()) {
return new ModelAndView("error/4xx");
}
if (status.is5xxServerError()) {
return new ModelAndView("error/5xx");
}
return null;
};
} https://docs.spring.io/spring-boot/reference/web/servlet.html#web.servlet.spring-mvc.error-handling |
According to the documentation of Spring Boot it is possible to define templates that should be used when a specific HTTP status code occurs.
I have noticed when I place a
404.jte
insrc/main/resources/templates/error
it doesn't work. I have tried the same thing with Thymeleaf and that does work.Digging through the Spring code I saw that in order to resolve the error view, it goes to the
DefaultErrorViewResolver#resolveError
, where there is a list oftemplateAvailabilityProviders
. These providers are Thymeleaf, Freemarker, Jsp, ... the supported templating engines of Spring (Boot).I looked for an easy way to register a custom JteTemplateAvailabilityProvider but found no such luck, the only reference in the Spring Code to for instance
ThymeleafTemplateAvailabilityProvider
is in the Spring autoconfiguration library, namely in theMETA-INF/spring.factories
file:I'm not that experienced with the autoconfiguration bits of Spring Boot, but I tried to add my own
META-INF/spring.factories
file in my own project:And the
JteTemplateAvailabilityProvider
class looks like this:This actually worked, when I place a debug point in
DefaultErrorViewResolver#resolveError
, I now see my own provider listed there as well and the JTE template is resolved properly.Although this works, I'm not sure it's logical that I add this to my own project, should this not be part of the jte-spring-boot-starter project?
I have tried making it more generic, using the
gg.jte.templateLocation
andgg.jte.templateSuffix
properties, while it works for the suffix, the templateLocation doesn't work.The text was updated successfully, but these errors were encountered: