user5685187
user5685187

Reputation:

spring boot static resource 404 error

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

Upvotes: 0

Views: 13010

Answers (2)

Yannic Bürgmann
Yannic Bürgmann

Reputation: 6581

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

Upvotes: 0

helospark
helospark

Reputation: 1460

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.

Upvotes: 2

Related Questions