thymeleaf-spring icon indicating copy to clipboard operation
thymeleaf-spring copied to clipboard

TemplateInputException

Open weissliufeng opened this issue 1 year ago • 1 comments

Version: spring-boot-starter-thymeleaf 2.0.9.RELEASE

for bugs: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [layouts/default], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [layouts/default], template might not exist or might not be accessible by any of the configured Template Resolvers

sample:

@RequestMapping({"news/{newsId}"}) public String news(Model model, @RequestHeader(name = "name", required = false) String name, @PathVariable("newsId") long newsId) { logger.info("{} read news {}", name, newsId);

        try {
            NewsDto newsDto = newsService.info2(newsId, name);
            model.addAttribute("newsId", newsId);
            model.addAttribute("news", newsDto.getInfo());
            model.addAttribute("content", newsDto.getContent());
            return "news";
        } catch (Exception e) {
            logger.error("error ", e);
            return "redirect:/404";
        }
    }

weissliufeng avatar Mar 13 '24 09:03 weissliufeng

Try giving full path of layouts/default template. Hope you would have a class for webconfig with WebMvcConfigurer, ApplicationContextAware interface implementation. There in SpringTemplateEngine set full path in AbstractConfigurationTemplateResolver instead of giving from web-inf.

vigneshsera avatar Apr 24 '24 09:04 vigneshsera