【发布时间】:2017-07-29 12:35:55
【问题描述】:
出于性能原因,Jetty 默认缓存静态资源,如属性文件。例如,像这样的一些代码:
public class FrontServlet extends HttpServlet
{
private final Properties routes = new Properties();
@Override
public void init()
throws ServletException
{
try {
this.routes.load(this.getClass().getClassLoader().getResourceAsStream("routes.properties"));
} catch (IOException | NullPointerException e) {
throw new ServletException(e);
}
}
}
即使在我删除 routes.properties 文件后仍会继续工作,因为它仍然可以从缓存中获得,而不是从磁盘中获得。 The Eclipse Jetty plugin documentation 也提到了这一点:寻找“禁用服务器缓存”。
现在,我想在开发环境中禁用此功能以避免误报。 The Jetty documentation 提到有一个名为 maxCacheSize 的初始化参数,如果设置为 0,则会禁用缓存。但是,我将它作为上下文参数进行了尝试:
<context-param>
<param-name>org.eclipse.jetty.servlet.maxCacheSize</param-name>
<param-value>0</param-value>
</context-param>
并作为 servlet 初始化参数:
<servlet>
...
<init-param>
<param-name>org.eclipse.jetty.servlet.maxCacheSize</param-name>
<param-value>0</param-value>
</init-param>
</servlet>
无济于事。
有人知道怎么做吗?
编辑:
即使在我重新启动 Web 服务器和运行它的 Vagrant 虚拟机之后,仍然可以找到 routes.properties 文件。我还应该提到我正在使用Maven Jetty plugin,因此使用mvn jetty:run 启动服务器。
【问题讨论】: