【问题标题】:Spring Boot does not serve a html pagesSpring Boot 不提供 html 页面
【发布时间】:2016-06-14 17:00:33
【问题描述】:

我正在开发单页 Angular 应用程序,现在我需要为我的客户提供静态 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”

【问题讨论】:

    标签: java spring spring-mvc spring-boot


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 2016-02-11
      • 2018-12-20
      • 2015-10-30
      • 1970-01-01
      • 2020-01-09
      • 2017-07-12
      • 2016-06-15
      • 1970-01-01
      相关资源
      最近更新 更多