jetty如何重新加载静态资源(html,css,jss)

时间:2015-03-03 03:14:14

标签: java spring jetty

我只是使用jetty来提供我的web项目而没有任何XML,但它仍然没有自动重新加载我设置的事件contextHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");

private void startJetty(int port) throws Exception {
    logger.debug("Starting server at port {}", port);
    Server server = new Server(port);
    server.setHandler(getServletContextHandler(getContext()));
    server.start();
    logger.info("Server started at port {}", port);
    server.join();
}

private static ServletContextHandler getServletContextHandler(WebApplicationContext context) throws Exception {
    WebAppContext contextHandler = new WebAppContext();
    contextHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
    contextHandler.getInitParams().put("cacheContro", "max-age=0, public");

    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath(CONTEXT_PATH);
    contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
    contextHandler.addEventListener(new ContextLoaderListener(context));
    contextHandler.setResourceBase(new ClassPathResource("static").getURI().toString());
    return contextHandler;
}

private static WebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation(CONFIG_LOCATION);
    context.getEnvironment().setDefaultProfiles(DEFAULT_PROFILE);
    return context;
}
PS:我的码头是版本9.2,我使用springmvc作为contextHandler,我在网站上尝试了很多方法和答案,例如https://gist.github.com/raymyers/5323304http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages,但仍然无效,我会等待解决方案。

0 个答案:

没有答案