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

mitkmikd  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(171)

我遵循本教程将Sping Boot 与AngularJS集成:
https://dzone.com/articles/java-8-springboot-angularjs-bootstrap-springdata-j
我在Eclipse/Photon中用STS构建了Sping Boot starter。我的Eclipse项目看起来像这样:
x1c 0d1x的数据
我的“Home”控制器看起来像这样:

  1. package com.example.demo.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. @Controller
  5. public class HomeController {
  6. @RequestMapping("/home")
  7. public String home() {
  8. return "index";
  9. }
  10. }

字符串
根据上面的截图,我在src/main/resources/static/views中有一个“index.html”。
我的application.properties定义了spring.mvc.view.prefix和.suffix:

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


当我右键单击Eclipse项目和“Run As > Spring App”时,没有错误或警告。
但是当我浏览localhost:8080/home时,我得到:

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


为什么我尝试访问“/home”时出现“404”?
在Eclipse中,我的Eclipse项目中有什么“特殊”需要做的吗?
有哪些好的故障排除策略?

ttygqcqt

ttygqcqt1#

我相信你没有使用模板引擎,如thymeleaf
尝试以下方法,它应该可以解决您的问题。
1.将您的index.html移动到src/main/resources/static。这是将自动提供HTML文件等静态资源的位置。
1.您可以删除在application.properties文件中定义的这两行。

相关问题