简体   繁体   中英

Cannot retrieve template in my Springboot application

The body of my index file looks like this:

<div class="container" style="width: 100% !important;">

    <!--Header-->
    <div th:replace="fragments/header :: header"></div>

    <!--Content-->
    <!--<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>-->

    <!--Footer-->
    <div th:replace="fragments/footer :: footer"></div>

</div>

It seems to be complaining about the line under my Header comment but I'm not sure why. What could be going on?

This is my error:

Mon Feb 06 16:06:26 CET 2017
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving fragment: "~{'fragments/header' :: header}": template or fragment could not be resolved (template: "index" - line 34, col 10)

Exception:

org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: "~{'fragments/header' :: header}": template or fragment could not be resolved (template: "index" - line 34, col 10)
    at org.thymeleaf.standard.expression.FragmentExpression.resolveExecutedFragmentExpression(FragmentExpression.java:593) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.standard.processor.AbstractStandardFragmentInsertionTagProcessor.computeFragment(AbstractStandardFragmentInsertionTagProcessor.java:368) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.standard.processor.AbstractStandardFragmentInsertionTagProcessor.doProcess(AbstractStandardFragmentInsertionTagProcessor.java:111) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:593) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
    at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:337) ~[thymeleaf-spring5-3.0.3.M1.jar:3.0.3.M1]
    at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:186) ~[thymeleaf-spring5-3.0.3.M1.jar:3.0.3.M1]
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1271) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:964) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:856) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:841) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at

Is there a file templates/fragments/header.html with a

< ... th:fragment="header">

in the classpath?

I'm not sure you can do that :

<!--<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>-->

Or maybe with pre-processing by prefixing and suffixing with double underscore.

Thymeleaf will process this line even if it's commented out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM