I'm starting an embedded tomcat via spring-boot and want to serve a static index.html page as part of a running application.
But the following does not work:
@SpringBootApplication public class HMyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } @RestController public class HomeContoller { @RequestMapping("/") public String index() { return "index"; } } src/main/resources/static/index.html Result: when I call localhost:8080, I just see the word "index", but not my html page. Why?
@RestControlleris a meta-annotation for@ControllerandResponseBody, meaning it writes "index" to the response input stream. You should use@Controllerinstead so that "index" will be resolved as a view name.@RestControllerside by side. Anyways I'm now getting the following exception using@Controller:javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'. It neither works returningindex.htmlinstead.static/index.htmlstatic/indexnorstatic/index.htmlworks.