2014-09-06 2 views
1

Я пытался использовать thymeleaf макет диалекте с Spring MVC, как указано в https://github.com/ultraq/thymeleaf-layout-dialect. Моя весна-сервлетов, как показано нижешаблон не может существовать или не могут быть доступны

<beans:bean id="templateResolver" 
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> 
    <beans:property name="prefix" value="/WEB-INF/templates/" /> 
    <beans:property name="suffix" value=".html" /> 
    <beans:property name="templateMode" value="HTML5" /> 
</beans:bean> 

<beans:bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine"> 
    <beans:property name="templateResolver" ref="templateResolver" /> 
    <!-- These lines add the dialect to Thymeleaf --> 
    <beans:property name="additionalDialects"> 
    <beans:set> 
     <beans:bean class="nz.net.ultraq.thymeleaf.LayoutDialect" /> 
    </beans:set> 
    </beans:property> 
</beans:bean> 

<beans:bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> 
    <beans:property name="templateEngine" ref="templateEngine" /> 
    <beans:property name="characterEncoding" value="UTF-8" /> 
</beans:bean> 

Я сохранил все файлы шаблона в/WEB-INF/шаблоны /. Когда я использую следующий код для создания и использования заманчивым thymeleaf

<html lang="en" xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
    layout:decorator="Layout.html"> 

Я получаю следующее сообщение об ошибке:

[THYMELEAF] * Dialect [1 of 2]: org.thymeleaf.spring3.dialect.SpringStandardDialect 
[THYMELEAF]  * Prefix: "th" 
[THYMELEAF] * Dialect [2 of 2]: nz.net.ultraq.thymeleaf.LayoutDialect 
[THYMELEAF]  * Prefix: "layout" 
[THYMELEAF] TEMPLATE ENGINE CONFIGURED OK 
19:32:40,992 INFO [org.thymeleaf.TemplateEngine] (http-localhost-127.0.0.1-8080-1) [THYMELEAF] TEMPLATE ENGINE INITIALIZED 
19:32:41,199 ERROR [org.thymeleaf.TemplateEngine] (http-localhost-127.0.0.1-8080-1) [THYMELEAF][http-localhost-127.0.0.1-8080-1] Exception processing template "home": Error resolving template "Layout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (home:4) 
19:32:41,202 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/expensemanager].[appServlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet appServlet threw exception: org.thymeleaf.exceptions.TemplateInputException: Error resolving template "MainLayout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (home:4) 

Если я не макет: декоратор = код «Layout.html» отлично работает без каких-либо ошибка.

Ниже изображение, которое показывает мою структуру проекта

enter image description here

ответ

0

Я обычно делаю это:

<beans:bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> 
    <beans:property name="characterEncoding" value="UTF-8" /> 
    <beans:property name="templateEngine"> 
    <beans:bean class="org.thymeleaf.spring3.SpringTemplateEngine"> 
     <beans:property name="additionalDialects"> 
     <beans:set> 
      <beans:bean class="nz.net.ultraq.thymeleaf.LayoutDialect" /> 
     </beans:set> 
     </beans:property> 
     <beans:property name="templateResolvers"> 
     <beans:bean class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> 
      <beans:property name="prefix" value="/WEB-INF/templates/" /> 
      <beans:property name="suffix" value=".html" /> 
      <beans:property name="templateMode" value="HTML5" /> 
     </beans:bean> 
     </beans:property> 
    </beans:bean> 
    </beans:property> 
</beans:bean> 

Если это не работает, вы можете разместить скриншот файла и папки состав?

+0

Я попробовал конфигурацию, но по-прежнему сталкивается с той же ошибки. Я добавил структуру проекта в сообщение, как вы просили. Пожалуйста, дайте мне знать, если я делаю что-то неправильно. – Prabhat

+0

В вашем файле HTML есть 'layout: decorator =" Layout.html ", но файл в структуре папок называется' MainLayout.html'. Есть где-то несоответствие? Если вы можете загрузить этот образец проекта, я могу взглянуть. Я думаю, что есть некоторая простая неправильная конфигурация. – manish

+0

Я скопировал файл войны на https://onedrive.live.com/redir?resid=EA49CD7184E0E40!172&authkey=!AI9iSfzen4xbBFw&ithint=file%2cwar, пожалуйста, взгляните на него и скажите мне, если я что-то неправильно сконфигурировал ... – Prabhat

Смежные вопросы