title: Thymeleaf with Spring MVC error No mapping found for HTTP request with URI
body: <p>I'm using a code downloaded from web, a sample of Spring MVC+Hibernate+Maven+Spring data and in this code the pages are jsp. Now I would like to introduce Thymeleaf instead of jsp si I have created an HTML greeting page but when I go on this page I obtain this error </p>
  
  <blockquote>
    <p>09:16:23.622 [http-nio-8080-exec-7] WARN  o.s.web.servlet.PageNotFound
    - No mapping found for HTTP request with URI [/dpr-data/WEB-INF/pages/greeting.html] in DispatcherServlet with name
    'dispatcher'</p>
  </blockquote>
  
  <p>These are my files code:</p>
  
  <p>Controller</p>
  
  <pre><code>package com.spr.controller;
  
  import java.util.List;
  
  import javax.validation.Valid;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.WebDataBinder;
  import org.springframework.web.bind.annotation.InitBinder;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import com.spr.exception.ShopNotFound;
  import com.spr.model.Shop;
  import com.spr.service.ShopService;
  import com.spr.validation.ShopValidator;
  
  @Controller
  @RequestMapping(value="/shop")
  public class ShopController {
  
      @Autowired
      private ShopService shopService;
  
      @Autowired
      private ShopValidator shopValidator;
  
      //Used to validate data
      @InitBinder
      private void initBinder(WebDataBinder binder) {
          binder.setValidator(shopValidator);
      }
  
      @RequestMapping(value="/create", method=RequestMethod.GET)
      public ModelAndView newShopPage() {
          ModelAndView mav = new ModelAndView("shop-new", "shop", new Shop());
          return mav;
      }
  
      //@Valid means that shop has to be validate
      @RequestMapping(value="/create", method=RequestMethod.POST)
      public ModelAndView createNewShop(@ModelAttribute @Valid Shop shop,
              BindingResult result,
              final RedirectAttributes redirectAttributes) {
  
          if (result.hasErrors())
              return new ModelAndView("shop-new");
  
          ModelAndView mav = new ModelAndView();
          String message = "New shop "+shop.getName()+" was successfully created.";
  
          shopService.create(shop);
          mav.setViewName("redirect:/index.jsp");
  
          redirectAttributes.addFlashAttribute("message", message);   
          return mav;     
      }
  
      @RequestMapping(value="/list", method=RequestMethod.GET)
      public ModelAndView shopListPage() {
          ModelAndView mav = new ModelAndView("shop-list.jsp");
          List&lt;Shop&gt; shopList = shopService.findAll();
          mav.addObject("shopList", shopList);
          return mav;
      }
  
      @RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
      public ModelAndView editShopPage(@PathVariable Integer id) {
          ModelAndView mav = new ModelAndView("shop-edit");
          Shop shop = shopService.findById(id);
          mav.addObject("shop", shop);
          return mav;
      }
  
      @RequestMapping(value="/edit/{id}", method=RequestMethod.POST)
      public ModelAndView editShop(@ModelAttribute @Valid Shop shop,
              BindingResult result,
              @PathVariable Integer id,
              final RedirectAttributes redirectAttributes) throws ShopNotFound {
  
          if (result.hasErrors())
              return new ModelAndView("shop-edit");
  
          ModelAndView mav = new ModelAndView("redirect:/index.html");
          String message = "Shop was successfully updated.";
  
          shopService.update(shop);
  
          redirectAttributes.addFlashAttribute("message", message);   
          return mav;
      }
  
      @RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
      public ModelAndView deleteShop(@PathVariable Integer id,
              final RedirectAttributes redirectAttributes) throws ShopNotFound {
  
          ModelAndView mav = new ModelAndView("redirect:/index.jsp");     
  
          Shop shop = shopService.delete(id);
          String message = "The shop "+shop.getName()+" was successfully deleted.";
  
          redirectAttributes.addFlashAttribute("message", message);
          return mav;
      }
  
      @RequestMapping(value="/greeting", method=RequestMethod.GET)
  public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
      model.addAttribute("name", name);
      return "greeting";
  }
  
  }
  </code></pre>
  
  <p>WebAppConfig:</p>
  
  <pre><code>    package com.spr.init;
  
  import java.util.*;
  import java.util.Properties;
  
  import javax.annotation.Resource;
  import javax.sql.DataSource;
  
  import org.thymeleaf.dialect.*;
  import org.hibernate.jpa.HibernatePersistenceProvider;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.support.ResourceBundleMessageSource;
  import org.springframework.core.env.Environment;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.jdbc.datasource.DriverManagerDataSource;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.view.JstlView;
  import org.springframework.web.servlet.view.UrlBasedViewResolver;
  import org.thymeleaf.spring4.SpringTemplateEngine;
  import org.thymeleaf.spring4.view.ThymeleafViewResolver;
  import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
  
  import nz.net.ultraq.thymeleaf.LayoutDialect;
  
  @Configuration
  @EnableWebMvc
  @EnableTransactionManagement
  @ComponentScan("com.spr")
  @PropertySource("classpath:application.properties")
  @EnableJpaRepositories("com.spr.repository")
  public class WebAppConfig {
  
      private static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";
      private static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";
      private static final String PROPERTY_NAME_DATABASE_URL = "db.url";
      private static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";
  
      private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
      private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
      private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "entitymanager.packages.to.scan";
  
      @Resource
      private Environment env;
  
      @Bean
      public DataSource dataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
  
          dataSource.setDriverClassName(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
          dataSource.setUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
          dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
          dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));
  
          return dataSource;
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          entityManagerFactoryBean.setDataSource(dataSource());
          entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
          entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
  
          entityManagerFactoryBean.setJpaProperties(hibProperties());
  
          return entityManagerFactoryBean;
      }
  
      private Properties hibProperties() {
          Properties properties = new Properties();
          properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
          properties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
          return properties;
      }
  
      @Bean
      public JpaTransactionManager transactionManager() {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
          return transactionManager;
      }
  
  //  @Bean
  //  public UrlBasedViewResolver setupViewResolver() {
  //      UrlBasedViewResolver resolver = new UrlBasedViewResolver();
  //      resolver.setPrefix("/WEB-INF/pages/");
  ////        resolver.setSuffix(".jsp");
  //      resolver.setViewClass(JstlView.class);
  //      return resolver;
  //  }
  
      @Bean
      public ResourceBundleMessageSource messageSource() {
          ResourceBundleMessageSource source = new ResourceBundleMessageSource();
          source.setBasename(env.getRequiredProperty("message.source.basename"));
          source.setUseCodeAsDefaultMessage(true);
          return source;
      }
  
      @Bean
      public ServletContextTemplateResolver templateResolver() {
          ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
          resolver.setPrefix("/");
          resolver.setSuffix(".html");
          resolver.setTemplateMode("HTML5");
          return resolver;
      }
  
      @Bean
      public SpringTemplateEngine templateEngine() {
          Set&lt;IDialect&gt; dialects = new HashSet&lt;IDialect&gt;();
          dialects.add(new LayoutDialect());
  
          SpringTemplateEngine engine = new SpringTemplateEngine();
          engine.setTemplateResolver(templateResolver());
          engine.setAdditionalDialects(dialects);
          return engine;
      }
  
      @Bean
      public ThymeleafViewResolver viewResolver() {
          ThymeleafViewResolver resolver = new ThymeleafViewResolver();
          resolver.setTemplateEngine(templateEngine());
          resolver.setOrder(1);
          resolver.setViewNames(new String[]{"*", "js/*", "template/*"});
          return resolver;
      }
  
  }
  </code></pre>
  
  <p>Initializer</p>
  
  <pre><code>package com.spr.init;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration.Dynamic;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.ContextLoaderListener;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  public class Initializer implements WebApplicationInitializer {
  
      private static final String DISPATCHER_SERVLET_NAME = "dispatcher";
  
      public void onStartup(ServletContext servletContext)
              throws ServletException {
          AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
          ctx.register(WebAppConfig.class);
          servletContext.addListener(new ContextLoaderListener(ctx));
  
          ctx.setServletContext(servletContext);
  
          Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                  new DispatcherServlet(ctx));
          servlet.addMapping("/");
          servlet.setLoadOnStartup(1);
      }
  
  }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"&gt;
  
      &lt;display-name&gt;spr-data&lt;/display-name&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>pom file</p>
  
  <pre><code>    &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;spr-data&lt;/groupId&gt;
      &lt;artifactId&gt;spr-data&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;spr-data&lt;/name&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;dpr-data&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          &lt;!-- Spring dependencies --&gt;
  
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;4.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
              &lt;version&gt;1.9.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Thymeleaf dependecies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-spring4&lt;/artifactId&gt;
              &lt;version&gt;2.1.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;nz.net.ultraq.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-layout-dialect&lt;/artifactId&gt;
              &lt;version&gt;1.3.0&lt;/version&gt;
          &lt;/dependency&gt;
  
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
              &lt;version&gt;1.8.6&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- dependency to fix JSPServletException --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-jsp-api&lt;/artifactId&gt;
              &lt;version&gt;8.0.26&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- Hibernate dependencies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
              &lt;version&gt;5.2.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- MySQL dependncies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.36&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.validation&lt;/groupId&gt;
              &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
              &lt;version&gt;1.1.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;jstl&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- slf4j --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;1.7.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- logback --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;version&gt;1.1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- log4jdbc --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.googlecode.log4jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;log4jdbc&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>project structure</p>
  
  <p><a href="https://i.stack.imgur.com/r9y2V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r9y2V.png" alt="http://i60.tinypic.com/mcccw9.png"></a></p>
  
  <p>what is the problem?Thanks</p>