代码之家  ›  专栏  ›  技术社区  ›  paulsm4

Spring Boot/Eclipse index.html:出现意外错误(type=Not Found,status=404)

  •  0
  • paulsm4  · 技术社区  · 7 年前

    我遵循本教程将Spring Boot与AngularJS集成:

    https://dzone.com/articles/java-8-springboot-angularjs-bootstrap-springdata-j

    我用Eclipse/Photon中的STS构建了Spring启动程序。我的Eclipse项目如下所示:

    enter image description here

    package com.example.demo.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class HomeController {
        @RequestMapping("/home")
        public String home() {
            return "index";
        }
    }
    

    根据上面的截图,我在src/main/resources/static/views中有一个“index.html”。

    My application.properties定义spring.mvc.view.prefix和.suffix:

    spring.mvc.view.prefix = /views/
    spring.mvc.view.suffix = .html
    

    但是当我浏览到localhost:8080/home时,我得到:

    Whitelabel Error Page
    
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    
    Sat Nov 03 13:40:19 PDT 2018
    There was an unexpected error (type=Not Found, status=404).
    No message available
    

    问:在我的Eclipse项目中,我需要在Eclipse中做什么“特别”的事情吗?

    提前谢谢!

    1 回复  |  直到 7 年前
        1
  •  1
  •   want2learn    7 年前

    我相信你没有使用模板引擎,如 thymeleaf .

    1. 移动你的 index.html src/main/resources/static . 这是静态资源 HTML 文件将自动送达。
    2. application.properties 文件。