Spring Cloud Zuul proxy Gateway does not load css, js from Spring Boot Application

被刻印的时光 ゝ 提交于 2020-01-06 03:41:28

问题


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

来源:https://stackoverflow.com/questions/52855451/spring-cloud-zuul-proxy-gateway-does-not-load-css-js-from-spring-boot-applicati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!