[英]Refresh static files served by SparkJava
I'm doing a project using Spark Java. 我正在使用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.
我想必须有一种方法可以在运行时刷新Spark Java的静态目录文件,以便可以实现运行时创建的映像请求。 Right?
对?
Thanks! 谢谢!
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.如果使用
staticFiles.location(...)
,意味着将静态文件保留在类路径中,则在构建应用程序时staticFiles.location(...)
静态资源复制到目标文件夹。 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.
解决方法是告诉Spark从src-directory的绝对路径读取静态文件。
So use staticFiles.externalLocation()
instead. 所以请改用
staticFiles.externalLocation()
。
我已经通过将png编码为Base 64并将其作为响应发送给客户端来解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.