0
votes

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
@SergiiGetman : i tried adding these two lines in applicationresource.properties but its still not working. spring.resources.chain.strategy.content.enabled=true spring.resources.chain.strategy.content.paths=/** - sourabh shinde
When i am using just a single level hierarchy in URL such as " /somepath" it works fine. but not working when i used 2 or 3 levels in URL - sourabh shinde
do you have some MvcConfig extends WebMvcConfigurerAdapter? - Sergii Getman
no, i am not using any MvcConfig extends WebMvcConfigurerAdapter - sourabh shinde

1 Answers

0
votes

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~!