Reputation: 129
I'm developing a simple Spring Boot app that uses Spring Boot Web. I placed my index.html into the templates subdirectory of the resources directory as per the Spring Boot docs. I've defined inside the application.properties file:
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
My WebMvcConfigurerAdapter looks like this:
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter{
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
super.addViewControllers(registry);
}
}
My problem is I cant seem to serve index.html at http://localhost:8080. I get the following error: "javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'".
How can I fix this without the use of a controller?
Kind regards, Dave
Upvotes: 0
Views: 925
Reputation: 12932
In order to serve static content from Spring Boot application you just need to place them in src/main/resources/static
- no other configuration needed.
index.html
to src/main/resources/static/index.html
application.properties
addViewControllers
method and @EnableWebMvc
annotation - you can actually delete whole classhttp://localhost:8080/
Upvotes: 1