问题描述
无法使用spring-boot加载非常简单的JSP页面,获得404 Not Found。
Can't load a very simple JSP page with spring-boot, getting 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返回welcome,但仍获得404。
Getting 404 even though debugger shows that "welcome" is being returned from the Controller RequestMapping.
此应用程序没有/ error的显式映射,所以你是看到
这是一个后备。
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Mar 07 19:35:15 2015年出现意外错误(类型=未发现
, status = 404)。
Sat Mar 07 19:35:15 EST 2015 There was an unexpected error (type=Not Found, status=404).
推荐答案
我需要将它添加到我的应用程序中。属性文件:
I needed to add this to my application.properties file:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
这篇关于spring-boot基本JSP 404未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!