0

I'm having problems in serving static content with spring-boot.

I have configured static content to be served through application.properties file like so:

static-location-path=/opt/myapp/static
spring.resources.static-locations=file:${static-location-path}/

Notice that it is outside of the jar file. Now if I launch my application with mvn spring-boot plugin like so:

mvn spring-boot:run -Drun.profiles=staging

Then the static files are served correctly, and I can access them.

But I do not want to run my application like this on the staging environment, but instead as a service, that can be automatically started on server boot. So I managed to build the application to a executable jar. Then I managed to launch it as an init.d service. The application is working otherwise correct, but it does no longer serve the static files. I checked, and the correct profile file (which determines which application.properties file should be used) should be loaded there correctly.

Main question is: How can I serve static content with spring-boot when the application is launched as a init.d service (jar), and I'm using application.properties configuration to serve the static content?

Maybe there's something I don't understand here. Supplementary questions related to this are:

  1. Are the different application.properties files (under resources folder) also bundled inside the jar? Which would mean they should be found, and application would get the correct configuration values from there?

  2. Can spring-boot serve static content at all when the application is bundled as jar and launched as a init.d service?

  3. How could I debug the problem more? I know where the app logs are being written, so that helps at least some.

Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106
  • Possible duplicate of [Thymeleaf + Spring-Boot - why can't I access static resources?](https://stackoverflow.com/questions/46324517/thymeleaf-spring-boot-why-cant-i-access-static-resources) – teppic Sep 30 '18 at 18:23
  • Doesn't seem like a duplicate: 1. I don't use thymeleaf, 2. The static content in my application is outside of resources folder and outside of the jar – Ville Miekk-oja Sep 30 '18 at 18:27
  • Retracted...... – teppic Sep 30 '18 at 18:30

1 Answers1

0

This is solved. The static content folder and files were not owned by the user which was used to run the service, so the user had no access to them. Too bad the error received was unclear (404), instead of some permission error.

Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106