java - spring-boot 基本 JSP 404 未找到

标签 java spring jsp spring-mvc spring-boot

无法使用 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/

相关文章:

java - 在java中减小图像的大小

java - applicationContext.xml 不读取 servletContext.contextPath

spring - Windows上的Docker,Mongodb,Spring Boot出现连接被拒绝错误

java - 在jsp中使用JSTL标签

java - 我想使用 jsp servlet 从 apachecommons 文件上传上传图像,但它会显示 java.lang.StringIndexOutOfBoundsException

java - 检索多个选择值

java - HystrixCommand 和 HystrixObservableCommand 的区别

java - 安装Eclipse时出现 “No repository found containing: …”错误消息怎么办?

java - 蓝牙无法连接到OBD2

java - Spring bean 使用外部属性文件初始化映射