Thymeleaf: Error Resolving Template -


i trying use layouts/templates thymeleaf i'm getting following exception.

exception processing template "user/index": error resolving template "/layouts/default.html", template might not exist or might not accessible of configured template resolvers 

here thymeleafconfig.java

@configuration public class thymeleafconfig {      @bean     public servletcontexttemplateresolver templateresolver() {         servletcontexttemplateresolver resolver = new servletcontexttemplateresolver();         resolver.setprefix("/web-inf/views/");         resolver.setsuffix(".html");         resolver.settemplatemode("html5");         resolver.setorder(1);         return resolver;     }      @bean     public springtemplateengine templateengine() {         springtemplateengine engine = new springtemplateengine();         engine.settemplateresolver(templateresolver());         engine.adddialect(new layoutdialect());         engine.adddialect(new springsecuritydialect());         engine.adddialect(new springstandarddialect());         return engine;     }      @bean     public thymeleafviewresolver thymeleafviewresolver() {         thymeleafviewresolver resolver = new thymeleafviewresolver();         resolver.settemplateengine(templateengine());         return resolver;     } } 

i have following folder structure

webapp/ ..web-inf/ ....views/ ......layouts/ ........default.html ......user ........index.html 

here default.html main layout.

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head>     <meta charset="utf-8" />     <meta http-equiv="x-ua-compatible" content="ie=edge" />     <meta name="viewport" content="width=device-width, initial-scale=1.0" />     <title>default</title>     <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> </head> <body>      <header>         header default.html     </header>      <section layout:fragment="content">         <p>content should go here!</p>     </section>      <footer>         footer default         <p layout:fragment="custom-footer">custom footer here!</p>     </footer>      <!-- scripts -->     <script src="https://code.jquery.com/jquery-2.1.3.min.js" />     <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>  </body> </html> 

here index.html

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"       layout:decorator="layouts/default.html"> <head>     <title>users</title> </head> <body> <section layout:fragment="content">     <p>this paragraph content page 1</p> </section> <footer>     <p layout:fragment="custom-footer">this footer content content page 1</p> </footer> </body> </html> 

they in different folders pathing should work unless i'm missing silly.

i found issue. if specify suffix in thymeleaf config not need .html extension.

@bean     public servletcontexttemplateresolver templateresolver() {         servletcontexttemplateresolver resolver = new servletcontexttemplateresolver();         resolver.setprefix("/web-inf/views/");         **resolver.setsuffix(".html");**         resolver.settemplatemode("html5");         resolver.setorder(1);         return resolver;     } 

it should be:

layout:decorator="layouts/default" 

instead of:

layout:decorator="layouts/default.html" 

i'm guessing looking layouts/default.html.html problem.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -