2
votes

I use spring boot 1.5.6 release, and thymeleaf 3.0.0.release, thymeleaf-layout-dialect 2.0.0.

I wrote a html file, like below. enter image description here

header_top and footer_bottom are another two html files, contents are: enter image description here

enter image description here

and I have a controller, it is very simple:

enter image description here

The start application are as below:

enter image description here

the applications.properties file cotains contents below: 
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.session.store-type=none

logging.level.root=INFO
logging.level.org.springframework.web=DEBUG
debug=true

When I run the app, I put http://localhost:8080 in the chrome address bar. What I got is hello world. So I guess the spring boot & thymeleaf template resolver can find the index.html file. But the header_top::catelog and footer_bottom::copy are not parsed at all. I checked the source code of the page through the chrome dev tools. the <div th:insert... are just as it is in the template files. So I guess the th:* are not parsed at all. I am new to spring boot and thymeleaf. I have googled for a long time, but still cannot find a solution.

Please anyone help me.

When request happens, the logs are as follows:

2017-08-25 10:56:35.023 DEBUG 34177 --- [nio-8080-exec-3] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@6333b70f 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/] 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path / 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.easylife.haozu.controller.IndexController.index(org.springframework.ui.Model)] 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/] is: -1 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*]) 2017-08-25 10:56:35.024 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'index' 2017-08-25 10:56:35.025 DEBUG 34177 --- [nio-8080-exec-3] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.thymeleaf.spring4.view.ThymeleafView@64c00234] based on requested media type 'text/html' 2017-08-25 10:56:35.025 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Rendering view [org.thymeleaf.spring4.view.ThymeleafView@64c00234] in DispatcherServlet with name 'dispatcherServlet' 2017-08-25 10:56:35.028 DEBUG 34177 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Successfully completed request 2017-08-25 10:56:35.028 DEBUG 34177 --- [nio-8080-exec-3] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@6333b70f

2
This might not be the issue, but, is it per specs for you to have the open and closed html, body and Doctype tags inside the header and footer files, factoring that you already have them in the main index? - yardie
@andre3wap that is not the problem because the piece of code inserted is only the one inside the th:fragment - juanlumn

2 Answers

0
votes

Could you try the insert in this way?

<div th:insert="header_top :: catalog"></div>

<div th:insert="footer_bottom :: copy"></div>

Also, the th namespace in header_top.html is incorrect, it should be:

xmlns:th="http://www.thymeleaf.org"

And could be great if you remove the unused xmlns:layout, just in case.

0
votes

Try to insert your fragments like this:

 <div th:replace="components/header_top :: catalog"></div>
 <div th:replace="components/footer_bottom :: copy"></div>

Where components/header_top and components/footer_bottom stand for paths to your HTML fragment files (it should be placed for example in templates folder of your application)

catalog and copy after :: are your fragments names (should be the same as your th:fragment names).