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

2 Answers2

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.

helospark
  • 1,420
  • 9
  • 12
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

Lucas
  • 14,227
  • 9
  • 74
  • 124
Yannic Bürgmann
  • 6,301
  • 5
  • 43
  • 77