Spring Boot不提供html页面

时间:2016-03-02 02:04:46

标签: java spring spring-mvc spring-boot

我正在开发单页角度应用程序,现在我需要将静态html索引页面提供给我的客户端,这就是我所做的:

我正在使用此配置:

    @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
    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";
     }

我使用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>

我通过此消息显示500服务器错误状态

  

无法在servlet中解析名称为“static / app / index.html”的视图   名称为“dispatcherServlet”

1 个答案:

答案 0 :(得分:-1)

知道了!问题出在@EnableWebMvc注释中 以下是documentation中参考的链接。