问题
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