I am using Thymeleaf to create a template for my web page and Spring. Here is the configuration in Spring app-servlet.xml :
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="order" value="1" />
<property name="viewNames" value="*.html,*.xhtml" />
</bean>
I have also a Controller with method :
@Controller
public class HomeController {
@RequestMapping(value="/")
public String index(){
return "index";
}
}
Here is the html page in webapp/WEB-INF/views/index.html :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
<title>Spring MVC Example</title>
</head>
<body>
<div th:include="templates/fragments/header::header"></div>
<h1>Hello on a second page!</h1>
<p>Click <a th:href="@{/hello}">here</a> to go back.</p>
<div th:include="templates/fragments/footer::footer"></div>
</body>
</html>
Here is the web.xml :
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/app-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
When i access to home page http://localhost:8080/app-web
i have the following error :
GRAVE: Servlet.service() for servlet [app] in context with path [/app-web] threw exception [Could not resolve view with name 'index' in servlet with name 'app'] with root cause
javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'app'
I don't understand because in Dispatcher, i load app-servlet.xml in which i have templateEngine and templateViewResolver which is configured in the directory WEB-INF/views and the .html extension. If someone could help, thanks