0

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.

7
  • check this two links : spring.io/guides/gs/serving-web-content docs.spring.io/spring-boot/docs/current/reference/htmlsingle/… Commented Oct 12, 2016 at 12:09
  • @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=/** Commented Oct 12, 2016 at 12:25
  • 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 Commented Oct 12, 2016 at 12:28
  • do you have some MvcConfig extends WebMvcConfigurerAdapter? Commented Oct 12, 2016 at 12:28
  • no, i am not using any MvcConfig extends WebMvcConfigurerAdapter Commented Oct 12, 2016 at 12:29

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.