2014-09-06 63 views
1

我一直試圖在https://github.com/ultraq/thymeleaf-layout-dialect中提到的spring mvc中使用百里香佈局方言。我的彈簧servlet如下模板可能不存在或可能不可訪問

<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/templates /中。當我用下面的代碼來創建和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 2014-09-10 19:58:35

+0

你的HTML文件有'layout:decorator =「Layout.html」',但文件夾結構中的文件被稱爲'MainLayout.html'。有什麼地方不匹配?如果你可以上傳這個示例項目,我可以看看。我認爲在某處存在一些簡單的錯誤配置。 – manish 2014-09-13 10:49:12

+0

我在https://onedrive.live.com/redir?resid=EA49CD7184E0E40!172&authkey=!AI9iSfzen4xbBFw&ithint=file%2cwar複製了war文件請看看它並告訴我是否我配置了一些東西... – Prabhat 2014-09-14 14:38:17

相關問題