1

当我的应用程序正在运行时,我无法保存正在服务的静态资产。这对于调试来说是一种痛苦,因为我希望在编辑 css、js 和 html 时能够刷新页面。

我认为listener.getFileCache().setEnabled(false);下面的行可以解决问题,但它仍然不允许我编辑这些文件。我在配置中还有什么遗漏吗?

在此处输入图像描述

这是我的申请...

    final HttpServer server = HttpServer.createSimpleServer(".", 8181);

    WebappContext ctx = new WebappContext("Socket", "/");

    //enable annotation configuration
    ctx.addContextInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
    ctx.addContextInitParameter("contextConfigLocation", "com.production");

    //allow spring to do all of it's stuff
    ctx.addListener("org.springframework.web.context.ContextLoaderListener");

    //enable web socket support
    final WebSocketAddOn addon = new WebSocketAddOn();
    for (NetworkListener listener : server.getListeners()) {
        listener.registerAddOn(addon);

        //if false, local files (html, etc.) can be modified without restarting the server
        listener.getFileCache().setEnabled(false);
    }

    //add jersey servlet support
    //@todo add spring support to jersey
    ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new ServletContainer());
    jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
    jerseyServletRegistration.setLoadOnStartup(1);
    jerseyServletRegistration.addMapping("/api/*");

    //add atmosphere servlet support
    AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
    AtmosphereFramework f = atmosphereServlet.framework();

    ReflectorServletProcessor r = new ReflectorServletProcessor();
    r.setServletClassName("com.sun.jersey.spi.spring.container.servlet.SpringServlet");

    f.addAtmosphereHandler("/socket/*", r);

    ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", atmosphereServlet);
    atmosphereServletRegistration.setInitParameter("org.atmosphere.websocket.messageContentType", "application/json");
    atmosphereServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
    atmosphereServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    //atmosphereServletRegistration.addMapping("/socket/*");
    atmosphereServletRegistration.setLoadOnStartup(1);

    //serve static assets
    StaticHttpHandler staticHttpHandler = new StaticHttpHandler("src/main/web");
    server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");

更新:

由于 AngularJS 的性质不需要成为 java 项目的一部分,我最终将我的 AngularJS 应用程序迁移到 java 世界之外。

4

0 回答 0