![v2-c034d3f5ba8005929536ad31e86e0fad_1440w.jpg?source=172ae18b](http://img-02.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic3.zhimg.com/v2-c034d3f5ba8005929536ad31e86e0fad_1440w.jpg?source=172ae18b)
Springboot集成jsp页面报404。最近搭建一个简单的Springboot+maven+jsp的项目时,出现访问jsp页面时一直出404,错误信息是:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Apr 15 10:44:30 CST 2020
There was an unexpected error (type=Not Found, status=404).
/index.jsp
翻译过来:
此应用程序没有/error的显式映射,因此您将其视为回退。
2020年4月15日星期三上午10:44:30
出现意外错误(类型=未找到,状态=404)。
/index.jsp索引
网上找了一些解决方案:
原因1:
Application启动类的位置不对.要将Application类放在最外侧,即包含所有子包
原因:spring-boot会自动加载启动类所在包下及其子包下的所有组件.
![v2-b514cc66f61af1291768ef38a08c6263_b.jpg](http://img-02.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic4.zhimg.com/v2-b514cc66f61af1291768ef38a08c6263_b.jpg)
不符合,pass掉
原因2:
在springboot的配置文件:application.yml或application.properties中关于视图解析器的配置问题:
当pom文件下的spring-boot-starter-paren版本高时使用:
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
当pom文件下的spring-boot-starter-paren版本低时使用:
spring.view.prefix=/
spring.view.suffix=.jsp
![v2-d2aba34be5ad0f9703eb22eef26c915f_b.jpg](http://img-03.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic4.zhimg.com/v2-d2aba34be5ad0f9703eb22eef26c915f_b.jpg)
![v2-58e8c1d48c82b456b5a83fabd7b5c1eb_b.jpg](http://img-02.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic4.zhimg.com/v2-58e8c1d48c82b456b5a83fabd7b5c1eb_b.jpg)
不符合,pass掉
原因3:
控制器的URL路径书写问题
@RequestMapping(“xxxxxxxxxxxxxx”)
实际访问的路径与”xxx”不符合.
![v2-d449c7e5615a751f6e96b272be5837f7_b.jpg](http://img-03.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic4.zhimg.com/v2-d449c7e5615a751f6e96b272be5837f7_b.jpg)
没有配置端口,使用默认8080:所以访问地址是:
![v2-90f84824fb7c6c7c8a36b3e77b211208_b.png](http://img-03.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic1.zhimg.com/v2-90f84824fb7c6c7c8a36b3e77b211208_b.png)
不符合,pass掉
最终通过配置idea的目录搞定:
![v2-2f9bf209e46868157e37ea6b4f0900e4_b.jpg](http://img-01.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic1.zhimg.com/v2-2f9bf209e46868157e37ea6b4f0900e4_b.jpg)
![v2-323b86de2d07b75f935ffc2991debd12_b.jpg](http://img-01.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic3.zhimg.com/v2-323b86de2d07b75f935ffc2991debd12_b.jpg)
修改箭头所指的为当前内容即可。如何没有该选项,maven clean 和 compile 完毕即可看到该内容。
![v2-7c77c316106e577b6ac801d332e0d178_b.jpg](http://img-02.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic1.zhimg.com/v2-7c77c316106e577b6ac801d332e0d178_b.jpg)
![v2-3adbd7e1e626e5c824eccae340c31482_b.png](http://img-01.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic3.zhimg.com/v2-3adbd7e1e626e5c824eccae340c31482_b.png)
![v2-c48be32667a8b7e19c53a69f893c6df5_b.jpg](http://img-01.proxy.5ce.com/view/image?&type=2&guid=eb94eb71-232f-eb11-8da9-e4434bdf6706&url=https://pic2.zhimg.com/v2-c48be32667a8b7e19c53a69f893c6df5_b.jpg)
作者:java小丑
原文链接: https:// blog.csdn.net/java_wxid /article/details/105530437