getClass()。getClassLoader()。getResourceAsStream()正在缓存资源 [英] getClass().getClassLoader().getResourceAsStream() is caching the resource

查看:220
本文介绍了getClass()。getClassLoader()。getResourceAsStream()正在缓存资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个资源(速度模板),我希望能够在开发过程中进行交换。但是,

I have a resource (velocity template) which I'd like to be able to swap during development. However,

getClass().getClassLoader().getResourceAsStream() 

似乎缓存模板。除了使用文件加载器而不是类加载器之外,有没有办法禁用它?

seems to cache the template. Is there a way to disable this besides using a file loader instead of the class loader?

推荐答案

为避免缓存,您可以使用:

To avoid caching you can use:

getClass().getClassLoader().getResource().openStream()

它等于使用 URLResourceLoader 代替 ClasspathResourceLoader 我想。我只想使用文件加载器。

It would be equal to using URLResourceLoader for Velocity instead of ClasspathResourceLoader I suppose. I would just go with a file loader.

这篇关于getClass()。getClassLoader()。getResourceAsStream()正在缓存资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆