title: No mapping found for HTTP request with URI [/WEB-INF/pages/MainPage.jsp] in DispatcherServlet with name 'dispatcherServlet'
body: <p>I am trying to configure Spring Boot using annotations.
  I have class </p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  @ComponentScan({
      ...
  })
  @EnableTransactionManagement
  @EnableAutoConfiguration
  @Import({ SecurityConfig.class })
  public class AppConfig extends SpringBootServletInitializer {...}
  </code></pre>
  
  <p>which contains this View resolver which works fine.</p>
  
  <pre><code>@Bean
  public InternalResourceViewResolver internalViewResolver() {
      InternalResourceViewResolver viewResolver
              = new InternalResourceViewResolver();
      viewResolver.setViewClass(JstlView.class);
      viewResolver.setPrefix("/WEB-INF/pages/");
      viewResolver.setSuffix(".jsp");
      viewResolver.setOrder(1);
      return viewResolver;
  }
  </code></pre>
  
  <p>But after receiving name of JSP file application raise this error:
  <strong>No mapping found for HTTP request with URI [/WEB-INF/pages/MainPage.jsp] in DispatcherServlet with name 'dispatcherServlet'.</strong></p>
  
  <p>I found solution for XML configuration:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt; 
  </code></pre>
  
  <p>But I am using annotation configuration, so this soultion is not suitable for me.</p>
  
  <p>I tried to resolve this problem extending AbstractAnnotationConfigDispatcherServletInitializer</p>
  
  <pre><code>public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] { AppConfig.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return null;
      }
  
      @Override
      //  I thought this method will be equivalent to XML config solution described above
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  
  }
  </code></pre>
  
  <p>But nothing has changed after this. By the way I looked at few examples with AbstractAnnotationConfigDispatcherServletInitializer, but I still don't understand how application can use this class when it's not annotated and no instances of this class are created. It's just declared and that's all. Maybe I need to create an instance of this class and attach it anywhere? </p>
  
  <p>Anyway I see in log this line: <strong>Mapping servlet: 'dispatcherServlet' to [/]</strong>
  So it looks like I have right servlet configuration.</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/26366806/no-mapping-found-for-http-request-with-uri-spring-4-1-annotation-configuration">this solution</a> but it doesn't help. I removed InternalResourceViewResolver and created application.properties with such content:</p>
  
  <pre><code>spring.view.prefix: /WEB-INF/jsp/
  spring.view.suffix: .jsp
  </code></pre>
  
  <p>But after that I received: <strong>javax.servlet.ServletException: Could not resolve view with name 'MainPage' in servlet with name 'dispatcherServlet'</strong></p>
  
  <p>So what is the proper way to resolve this problem?</p>
  
  <p><strong>UPDATE</strong>
  I tried to create a new simple project from scratch.</p>
  
  <p><strong>pom.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;edu.springtest&lt;/groupId&gt;
      &lt;artifactId&gt;SpringTest&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt;
      &lt;/parent&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Main.java</strong>:</p>
  
  <pre><code>@Controller
  @Configuration
  @ComponentScan
  @EnableAutoConfiguration
  @SpringBootApplication
  public class Main {
      @RequestMapping("/")
      String home() {
          return "hello";
      }
  
      public static void main(String[] args) throws Exception {
          SpringApplication.run(Main.class, args);
      }
  }
  </code></pre>
  
  <p><strong>application.properties</strong>:</p>
  
  <pre><code>spring.view.prefix: /WEB-INF/jsp/
  spring.view.suffix: .jsp
  </code></pre>
  
  <p>Project's structure:</p>
  
  <p><img src="https://i.stack.imgur.com/I1Ewg.png" alt="Project&#39;s structure"></p>
  
  <p>I run project with command mvn spring-boot:run and receive
  <strong>edu.test.Main: Started Main in 2.365 seconds (JVM running for 5.476)</strong> in output.
  But when I'm opening localhost:8080 I receive:</p>
  
  <pre><code>Whitelabel Error Page
  
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  Sat Dec 20 11:25:29 EET 2014
  There was an unexpected error (type=Not Found, status=404).
  No message available
  </code></pre>
  
  <p>But now I'm not receiving "No mapping found..." error in output. When I am opening localhost:8080 nothing is printed to output at all.
  So what am I doing wrong?</p>