title: Configure react to be served on Spring boot app
body: <p>So far, I've been writing a bunch of endpoints for my Spring boot app, with no html UI side. Now, I want to serve the HTML file and js files which contain react code.</p>
  
  <p>When I visit <code>http://localhost:8443</code> I get:</p>
  
  <pre><code>Whitelabel Error Page
  
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  
  Sun Nov 19 11:54:01 PST 2017
  There was an unexpected error (type=Not Found, status=404).
  Not Found
  </code></pre>
  
  <p>What I did so far: </p>
  
  <p>1.Added a web config class that extends <code>WebMvcConfigurerAdapter</code>:</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  public class WebConfig extends WebMvcConfigurerAdapter {
      @Bean
      public ViewResolver internalResourceViewResolver() {
          InternalResourceViewResolver bean = new InternalResourceViewResolver();
          bean.setPrefix("/resources/static/");
          bean.setSuffix(".html");
          return bean;
      }
  }
  </code></pre>
  
  <p>2.Added a rest controller endpoint: </p>
  
  <pre><code>@RestController
  public class HomeController {
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public ModelAndView getdata() {
          ModelAndView model = new ModelAndView("index");
          return model;
      }
  }
  </code></pre>
  
  <p>I have <code>myproject/src/main/resources/static/index.html</code> file in my project.</p>