1
我在集成Spring MVC 3 + Thymeleaf + Apache Tiles時遇到了以下錯誤。Spring MVC3 + Apache tiles + Thymeleaf集成問題
我想打開一個login.html,它擴展了佈局定義。
錯誤解決模板「/WEB-INF/templates/layout.html」,模板可能不存在或可能無法訪問任何配置的模板解析器
請給我建議的解決方案
以下是我的代碼片段
的web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Thymeleaf Tiles Example</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
disptacher- servlet.xml中
個<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.bosch.chandan.springpoc.controller" />
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<property name="additionalDialects">
<set>
<bean
class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect" />
<bean class="org.thymeleaf.extras.tiles2.dialect.TilesDialect" />
</set>
</property>
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="viewClass" value="org.thymeleaf.extras.tiles2.spring3.web.view.ThymeleafTilesView"/>
<property name="templateEngine" ref="templateEngine" />
<property name="order" value="1"></property>
</bean>
<bean id="tilesConfigurer"
class="org.thymeleaf.extras.tiles2.spring3.web.configurer.ThymeleafTilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
</beans>
的layout.html
<!DOCTYPE html>
<html xmlns:tiles="http://www.thymeleaf.org">
<head>
</head>
<body>
<div tiles:include="header">Header Block</div>
<div tiles:substituteby="body">Body Block</div>
<div tiles:substituteby="footer">Footer Block</div>
</body>
</html>
磚,def.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="layout" template="/WEB-INF/templates/layout.html">
<put-attribute name="header" value="/WEB-INF/templates/header.html"></put-attribute>
<put-attribute name="body" value="/WEB-INF/templates/Mainhome.html"></put-attribute>
<put-attribute name="footer" value="/WEB-INF/templates/footer.html"></put-attribute>
</definition>
<definition name="login" extends="layout">
</definition>
</tiles-definitions>
的login.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body bgcolor="#66FF99">
<form action="" method="post">
<fieldset>
<legend>Enter Login Details</legend>
</fieldset>
</form>
</body>
</html>
從WEB-INF移動後添加我的項目結構以及到webapps .. 我應該移動我的tiles-def.xml文件嗎?
我將我的模板從web-inf移至webapps,但問題仍然存在。 – user1659239