2

I have created a gateway application using Spring Cloud Zuul proxy. The gateway application working fine but it is not loading static files like img,css and js files.

I have added below setting in my application.properties file of my gateway application zuul.routes.demo.url=http://localhost:8091 where demo is the value of spring.application.name property of my spring boot application.

If i run my spring boot application, then all css or js or static files like img loads perfectly fine. But when I access the same application using Zuul, it is not working.

Currently I have placed my static files like img under src/main/resources/META-INF/resources/WEB-INF/resources/img/

Following are the things I have tried/my observation.

1) Tried using strip-prefix: false property in gateway application.
2) I also tried placing img file under src/main/webapp/static/ and src/main/resources/static/
3) The img link from my application and gateway application is as follows

Actual Application : http://localhost:8091/img/test.svg ( Works fine)
Via Gateway application : http://localhost:8080/img/test.svg (GET http://localhost:8080/img/test.svg 404 error message)

Update

Found one alternative solution

For example in your gateway application, you have placed the application name or application context as "demo"

then all your static files in your spring boot application needs to be under "demo" directory i.e. src- main – resources – static -demo

I have just documented here for any one reference http://kotreshtm.blogspot.com/2018/10/serving-static-files-from-spring-boot.html

If any better solution/ approach, please suggest.

Any suggestions are appreciated. Thank you

  • I have the same problem, then checked you solution by putting static resource under resources/static/demo, but again i got 404 error! – Rasool Ghafari Jul 20 '20 at 08:26

0 Answers0