title: Spring MVC integration Thymeleaf
body: <p>I have a problem. I created Spring MVC + Thymeleft project but can't integrate properly, I read many guides and documentations, but nothing to help me. What's problem? Page load and no errors but no relevant information.. My code:</p>
  
  <p><strong>spring.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/practick" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate 3 Annotation SessionFactory Bean definition--&gt;
  &lt;bean id="hibernate3AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;SpringMVC1.model.Store&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
              &lt;prop key="hibernate.enable_lazy_load_no_trans"&gt;false&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;mvc:resources mapping="/SpringMVC1/**" location="/WEB-INF/views" /&gt;
  
  &lt;!-- class beans --&gt;
  &lt;bean id="storeDAO" class="SpringMVC1.dao.Impl.StoreDAOImpl"&gt;
      &lt;property name="sessionFactory" ref="hibernate3AnnotatedSessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="storeModel" class="SpringMVC1.model.Store"&gt;
  &lt;/bean&gt;
  
  &lt;!-- Thymeleaf --&gt;
  &lt;bean id="templateResolver"
        class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"&gt;
      &lt;property name="prefix" value="/views/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
      &lt;property name="templateMode" value="HTML5" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="templateEngine"
        class="org.thymeleaf.spring3.SpringTemplateEngine"&gt;
      &lt;property name="templateResolver" ref="templateResolver" /&gt;
      &lt;property name="additionalDialects"&gt;
          &lt;set&gt;
              &lt;bean class = "org.thymeleaf.spring3.dialect.SpringStandardDialect"/&gt;
          &lt;/set&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"&gt;
      &lt;property name="templateEngine" ref="templateEngine" /&gt;
      &lt;property name="order" value="1" /&gt;
      &lt;property name="viewNames" value="*.html,*.xhtml,*.jsp" /&gt;
      &lt;property name="excludedViewNames"&gt;
          &lt;array&gt;
              &lt;value&gt;home.jsp&lt;/value&gt;
          &lt;/array&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>In <strong>pom.xml</strong> insert dependency:</p>
  
  <pre><code>&lt;!-- Thymeleaf --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf&lt;/artifactId&gt;
          &lt;version&gt;2.1.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf-spring3&lt;/artifactId&gt;
          &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>Prototype of controller</strong></p>
  
  <pre><code>@Controller
  public class HomeController {
  
  @Autowired
  private ServletContext servletContext;
  
  TemplateEngine templateEngine;
  
  private static Store store;
  private static StoreDAOImpl storeDAOImpl;
  static List&lt;Store&gt; storess;
  
  static{
      ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
      storeDAOImpl = (StoreDAOImpl)context.getBean("storeDAO");
      store = (Store)context.getBean("storeModel");
  }
  
  /*
  @RequestMapping(value="/home")
  public ModelAndView handleRequest(HttpServletRequest req,
                                    HttpServletResponse resp) throws Exception {
  
      ModelAndView modelAndView = new ModelAndView("home");
      //modelAndView.addObject("storeList", storeDAO.getAllStores());
  
      return modelAndView;
  }
  
      @RequestMapping(value = "/storeModel")
      public ModelAndView root(@PathVariable String appBeanId, Locale locale,
                         org.springframework.ui.Model model) {
          appBeanId="storeModel";
          locale.getCountry();
          store.setName("store1");
          model.addAttribute("store1", store);
          return new ModelAndView("home");
      }
  */
  private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
  
  @RequestMapping(value = "/home")
  public String login(@Validated Store store, Model model) {
      model.addAttribute("storeName", "sometext");
      return "home";
  }
  
  
  /*
  //public static List stores = storeDAOImpl.getAllStores();
  
  @RequestMapping(value = "/listStores")
  public ModelAndView y(HttpServletRequest req,
                        HttpServletResponse resp) throws SQLException, IOException {
      store.setName("store1");
      WebContext webContext = new WebContext(req, resp, servletContext);
      webContext.setVariable("stores", storeDAOImpl.getAllStores());
      webContext.setVariable("store1", store);
      return new ModelAndView("home");
  }
  */
  }
  </code></pre>
  
  <p>And <strong>home.jsp</strong>:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Hello World!&lt;/h1&gt;
      &lt;p&gt;This is the stores!&lt;/p&gt;
   &lt;!--       &lt;c:forEach items="${storeList}" var="store"&gt;
          ${store.name} ${store.type}: ${store.address}
          &lt;br /&gt;
      &lt;/c:forEach&gt;
   --&gt;
  &lt;table&gt;
      &lt;caption&gt; Store #2&lt;/caption&gt;
      &lt;tr&gt;&lt;/tr&gt;
          &lt;td&gt;&lt;span th:text = "${storeName}"&gt;0&lt;/span&gt;&lt;/td&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4oay7.png" alt="web">
  <img src="https://i.stack.imgur.com/Zh27h.png" alt="project structure"></p>