Spring Boot Request mapping not loading static resources

时光毁灭记忆、已成空白 提交于 2019-12-12 01:15:34

问题


I have a spring boot application where I serve some static jsp pages stored in directory src/main/webapp which includes some javascript references stored under directory "src/main/resources/static". When I do the requestmapping for "/somepath" then it successfully returns view that has javascript references in static resources folder such as "src/main/resources/static/lib/script.js"

But the problem that I'm facing right now is when I do the @requestmapping to "/sompath/xyz" then I get HTTP 404 error. When I inspected the page source then I found out that the page was searching for static folder in this path "/somepath/lib/script.js" that is "/somepath" is getting prefixed to the default resources location. Is there any way that I could map these URIs such that no matter how many "/path/" are there, it will look for resources under the "/static/" folder only and not like "/static/path"

Any help is appreciated. I apologise for my problem structure as I'm a beginner and I'm still learning to put all these things in better perspective. Thanks in advance.


回答1:


I have same problem I found the way but its half solution.

first

use RequestMapping path depth just one like 'spring'

It is work well every situation.

second

use RequestMapping path depth tow like 'spring/xyz' and <link src="../some.css"/>

last

use depth 3 'spring/xyz/123' and <link src="../../some.css"/>

This all is messed up but it is working.

So I open the question on stack overflow again here please anyone come and check this and leave some idea thanks~!



来源:https://stackoverflow.com/questions/39997358/spring-boot-request-mapping-not-loading-static-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!