0
votes

I am developing single page angular application, right now i need to serve the static html index page to my client, this is what i have done:

I am using this configuration:

    @Configuration
    @EnableAutoConfiguration
    @EnableWebMvc
    @EnableCaching
    @ComponentScan(basePackages = "com.example.*")
    public class DemoJPAConfig extends WebMvcConfigurerAdapter {

        @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
                                 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
.
.
.

Controller: */

    @Controller
    public class MainController {
    //mapping for index html template        
    @RequestMapping("/")
    public String getIndexPage() {
           return "static/app/index.html";
    }
    //mapping for all other templates
    @RequestMapping("/templates/{name}/{component}")
        public String getPage(@PathVariable("name") String name,
                              @PathVariable("component") String component) {
            return "/static/"+name + "/"+component+".html";
     }

I use spring boot 1.3.2

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>

I recive 500 server error status with this message

Could not resolve view with name 'static/app/index.html' in servlet with name 'dispatcherServlet'

1

1 Answers

-1
votes

Got it! The problem was in @EnableWebMvc annotation Here is a link to the reference in the documentation.