Spring Boot项目根路径GET请求返回NotFound错误排查求助
Spring Boot应用无法返回网页,访问"/"报NotFound错误
我的简单Spring Boot应用无法返回网页,向映射路径“/”发送GET请求时收到NotFound错误。以下是相关代码与配置:
Controller类
@Controller public class Store { @RequestMapping(value = "/", method = RequestMethod.GET) public String home() { return "home"; } }
application.properties配置(指定视图文件位置)
spring.mvc.view.prefix=/view/ spring.mvc.view.suffix=.html
home.html文件内容
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Store</title> </head> <body> <h1>Hello</h1> </body> </html>
home.html位于webapp下的view文件夹中。按预期访问localhost:8080应加载首页,但实际无法实现,寻求帮助。
更新
将HTML文件从home.html重命名为index.html并移到webapp文件夹后,应用能正常运行,但控制器方法仍未被调用。这是因为Spring默认将index.html映射为首页的特性。
最终更新
在Eclipse中重新创建该项目(之前用STS4创建),无需修改任何内容即可正常运行,推测是STS4的配置问题。建议遇到类似问题的开发者检查IDE配置,问题可能不在代码本身。
内容的提问来源于stack exchange,提问作者Splotchy
相关产品推荐
相关产品推荐

