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.
When I visit http://localhost:8443 I get:
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
What I did so far:
1.Added a web config class that extends WebMvcConfigurerAdapter:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver internalResourceViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/resources/static/");
bean.setSuffix(".html");
return bean;
}
}
2.Added a rest controller endpoint:
@RestController
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView getdata() {
ModelAndView model = new ModelAndView("index");
return model;
}
}
I have myproject/src/main/resources/static/index.html file in my project.
