0

I am studying spring boot. And now I have to deploy my static resources to the web project, linking it, but it returns 404 error

enter image description here

Also, when I access to "localhost:8080/appie/resources/js/common.js" browser returns 404 error(my context path is /appie).

What could be that reason?

server.contextPath=/appie
4
  • What is your context path? Commented Nov 24, 2017 at 8:56
  • "appie" is my context path Commented Nov 24, 2017 at 9:02
  • Do not post images of code or errors! Commented Nov 24, 2017 at 9:03
  • my bad, i will edit it Commented Nov 24, 2017 at 9:05

2 Answers 2

2

Spring Boot by convention serves static resources under src/main/resources/static. The path of the resource will be relative to this, so if you put common.js under static resources, you will be able to access to it in: localhost:8080/appie/common.js

To access to it in as resources/js/common.js create this folder structure under static.

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

1 Comment

Thank you for your answer, now i can go on.
0

You should read this guide about serving static content with spring boot.

It says the following:

Spring Boot will automatically add static web resources located within any of the following directories:

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

After placing your js file in one of this directories you can access it via $host:$port/$contextPath/common.js

Comments

Your Answer

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