title: Spring Boot, Java Config - No mapping found for HTTP request with URI [/...] in DispatcherServlet with name 'dispatcherServlet'
body: <p>This has been a quite common problem here in stackOverflow, but none of the topics of the same problem solves mine.</p>
  
  <p>We have a template configuration that uses xml config, but now we're trying to move away from that and start using Java config.</p>
  
  <p>So I have a new project using Java config and Spring Boot. We're also using JSP and Tiles 3.</p>
  
  <p>Problem is: it fails to render our admin login page.</p>
  
  <p>Here is the code:</p>
  
  <p>Main config class:</p>
  
  <pre><code>@SpringBootApplication
  @EnableScheduling
  @Import(OnAdminBeans.class)
  public class AppConfig extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(AppConfig.class, args);
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(AppConfig.class);
      }
  }
  </code></pre>
  
  <p>The <code>AppConfig.class</code> is is the main package. Through the <code>@ComponentScan</code> that <code>@SpringBootApplication</code> brings, it scans the other configurations that are on <code>mainpackage.config</code>, so it imports the view config class:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class ViewConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/adm/static/**").addResourceLocations("/adm/static/");
      }
  
  //  @Override
  //  public void addViewControllers(ViewControllerRegistry registry) {
  //      registry.addViewController("/adm/login").setViewName("login-template-tiles");
  //  }
  
      @Override
      public void configureViewResolvers(ViewResolverRegistry registry) {
          registry.viewResolver(viewResolver());
          registry.viewResolver(jspViewResolver());
          registry.viewResolver(tilesViewResolver());
      }
  
      @Bean
      public LocaleResolver localeResolver() {
          CookieLocaleResolver localeResolver = new CookieLocaleResolver();
          localeResolver.setCookieName("locale");
          localeResolver.setCookieMaxAge(30);
          localeResolver.setDefaultLocale(new Locale("pt", "BR"));
          return localeResolver;
      }
  
      @Bean
      public MultipleViewResolver viewResolver() {
          Map&lt;String, ViewResolver&gt; viewsResolvers = new HashMap&lt;String, ViewResolver&gt;();
          viewsResolvers.put(MultipleViewResolver.ViewType.JSP.getKey(), jspViewResolver());
          viewsResolvers.put(MultipleViewResolver.ViewType.TILES.getKey(), tilesViewResolver());
  
          MultipleViewResolver viewResolver = new MultipleViewResolver();
          viewResolver.setViewsResolvers(viewsResolvers);
          viewResolver.setOrder(1);
          return viewResolver;
      }
  
      @Bean
      public InternalResourceViewResolver jspViewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setPrefix("/WEB-INF/jsp/");
          viewResolver.setSuffix(".jsp");
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setOrder(2);
          return viewResolver;
      }
  
      @Bean
      public UrlBasedViewResolver tilesViewResolver() {
          UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
          viewResolver.setViewClass(TilesView.class);
          viewResolver.setOrder(3);
          return viewResolver;
      }
  
      @Bean
      public TilesConfigurer tilesConfigurer() {
          TilesConfigurer configurer = new TilesConfigurer();
          configurer.setDefinitions("/WEB-INF/tile-defs/tiles-definitions.xml");
          return configurer;
      }
  }
  </code></pre>
  
  <p>The <code>LoginController.class</code> is defined as:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/adm")
  public class LoginController {
  
      @RequestMapping(value = "/login")
      public ModelAndView login() {
          return new ModelAndView("login-template-tiles");
      }
  }
  </code></pre>
  
  <p>And in <code>tiles-definitions.xml</code> I have the following definition for login-template-tiles:</p>
  
  <pre><code>&lt;definition name="login-template-tiles" template="/WEB-INF/jsp/adm/templates/login-template.jsp"&gt;
          &lt;put-attribute name="admin-title" value="Admin" /&gt;
          &lt;put-attribute name="content" value="/WEB-INF/jsp/adm/templates/sections/login/index.jsp" /&gt;
      &lt;/definition&gt;
  </code></pre>
  
  <p>Note that both files exist.</p>
  
  <p>Given all that the <em>LoginController.login()</em> <strong>does get called</strong> when i try to access <em>/adm/login</em>. But it fails to find the proper jsp file, aparently.</p>
  
  <p>It returns a <strong>404</strong>. With TRACE enabled, I get the following log:</p>
  
  <pre><code>DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/adm/templates/login-template.jsp]
  
  Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@2118c09a] in DispatcherServlet with name 'dispatcherServlet'
  
  Looking up handler method for path /WEB-INF/jsp/adm/templates/login-template.jsp
  
  Did not find handler method for [/WEB-INF/jsp/adm/templates/login-template.jsp]
  
  Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@2c148974] in DispatcherServlet with name 'dispatcherServlet'
  
  No handler mapping found for [/WEB-INF/jsp/adm/templates/login-template.jsp]
  
  Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@784c3547] in DispatcherServlet with name 'dispatcherServlet'
  
  No handler mapping found for [/WEB-INF/jsp/adm/templates/login-template.jsp]
  
  Testing handler map [org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@533e0604] in DispatcherServlet with name 'dispatcherServlet'
  
  Testing handler map [org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@cfd1b4e] in DispatcherServlet with name 'dispatcherServlet'
  
  No mapping found for HTTP request with URI [/WEB-INF/jsp/adm/templates/login-template.jsp] in DispatcherServlet with name 'dispatcherServlet'
  </code></pre>
  
  <p>Any suggestions are appreciated!</p>
  
  <p><strong>EDIT:</strong>
  Ok. By debugging, I found out that it has something to do with the embedded Tomcat. Other than that, I have no clue what is going on.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Found that the problem is in <strong>org.springframework.web.servlet.DispatcherServlet#getHandler</strong>. It simply doesn't find a HandlerMapping for that request. Do I have to register one?</p>