Refresh static files served by SparkJava

前提是你 提交于 2019-12-12 11:05:43

问题


I'm doing a project using Spark Java. On the server side, some images are created and I want them to be available in the client. Since I have a static content directory, after creating the image on the server side, I place it in that directory. However, this file is not available unless I reboot the server. I guess there must be a way to refresh the static directory file for Spark Java on runtime so that requests of on-runtime created images can be fulfilled. Right?

Thanks!


回答1:


The documentation says:

If you use staticFiles.location(...), meaning you keep your static files in the classpath, static resources are copied to a target folder when you build your application. This means you have to make/build your project in order to refresh static files. A workaround for this is to tell Spark to read static files from the absolute path to the src-directory.

So use staticFiles.externalLocation() instead.




回答2:


I've solved it by encoding the png as Base 64 and send it as response to the client.



来源:https://stackoverflow.com/questions/32181702/refresh-static-files-served-by-sparkjava

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