无法使用 spring-boot 加载一个非常简单的 JSP 页面,得到 404 Not Found。
src/main/java/SampleWebJspApplication.java
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleWebJspApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspApplication.class, args);
}
}
src/main/java/WebController.java
@Controller
public class WebController {
@RequestMapping("/")
public String welcome() {
return "welcome";
}
}
src/main/webapp/WEB-INF/jsp/welcome.jsp
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<body>
<h1>Hello.</h1>
</body>
</html>
即使调试器显示 Controller RequestMapping 正在返回“欢迎”,也会出现 404。
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Mar 07 19:35:15 EST 2015 There was an unexpected error (type=Not Found, status=404).
最佳答案
我已经尝试了很多解决方案,但找不到有效的解决方案。
如果您正在使用 Intellij IDEA 并且在您抓头发时阅读本文:请勿尝试使用 IDE 的运行 ▶︎ 按钮运行 Spring Boot 应用程序(具有动态 .jsp View )。
$ cd {your_project_folder_path}
$ ls //Check if you are in the same place with the pom.xml
然后输入
$ mvn spring-boot:run
现在您的应用程序在 localhost:8080
上提供服务。
关于java - spring-boot 基本 JSP 404 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28922248/