今天在布置项目时出现一个问题,就是我在一台新电脑上从git上下载一个SpringBoot项目,然后布置完成之后,启动成功,但是在访问首页登录页面时,报错如下:
2018-04-28 15:46:34.457 INFO 596 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8070 (http)
2018-04-28 15:46:34.468 INFO 596 --- [ restartedMain] com.binggou.fa.FaApplication : Started FaApplication in 19.553 seconds (JVM running for 20.431)
2018-04-28 15:46:34.469 INFO 596 --- [ restartedMain] com.binggou.fa.FaApplication : FaApplication is success!
2018-04-28 15:46:49.361 INFO 596 --- [nio-8070-exec-6] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-04-28 15:46:49.361 INFO 596 --- [nio-8070-exec-6] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-04-28 15:46:49.434 INFO 596 --- [nio-8070-exec-6] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 73 ms
2018-04-28 15:46:49.468 INFO 596 --- [nio-8070-exec-6] a.s.s.m.AbstractValidatingSessionManager : Enabling session validation scheduler...
2018-04-28 15:46:49.606 WARN 596 --- [nio-8070-exec-6] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/WEB-INF/view/login.html] in DispatcherServlet with name 'dispatcherServlet'
2018-04-28 15:46:49.774 WARN 596 --- [nio-8070-exec-6] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/WEB-INF/view/404.html] in DispatcherServlet with name 'dispatcherServlet'
前端页面显示为404,这个项目是有这个页面的,如图:
而且这个项目我在别的很多电脑上都是能够运行成功的,但是在这个环境的电脑上报404,说明不是项目代码的问题,应该是环境问题,后来经过同事的指点,解决问题,问题原因是,在这个环境中idea没有把上面的webapp目录当成一个静态资源目录,所以即便重启,也找不到对应的文件。解决如下:
1.按住组合键Shift+Ctrl+Alt+S
调出如下页面:
2.选择你要启动的项目,选择中间的资源目录:
3.重启项目,运行即可