Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在main()中指定带有大气的Spring Servlet_Java_Spring_Sockets_Atmosphere - Fatal编程技术网

Java 如何在main()中指定带有大气的Spring Servlet

Java 如何在main()中指定带有大气的Spring Servlet,java,spring,sockets,atmosphere,Java,Spring,Sockets,Atmosphere,目前我在main()方法中实现atmosphere,如下所示 public static void main(String[] args) throws IOException { final HttpServer server = HttpServer.createSimpleServer(".", 8181); WebappContext ctx = new WebappContext("Socket", "/"); //allow spring to do al

目前我在main()方法中实现atmosphere,如下所示

public static void main(String[] args) throws IOException {
    final HttpServer server = HttpServer.createSimpleServer(".", 8181);

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

    //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
        //@todo experiment with this setting in production vs development
        listener.getFileCache().setEnabled(false);
    }

    //add jersey servlet support
    ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new ServletContainer());
    //jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "come.fettergroup.production.queue.resources");
    jerseyServletRegistration.setLoadOnStartup(1);
    jerseyServletRegistration.addMapping("/api/*");

    //add atmosphere servlet support
    ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", new AtmosphereServlet());
    atmosphereServletRegistration.setInitParameter("org.atmosphere.websocket.messageContentType", "application/json");
    atmosphereServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    atmosphereServletRegistration.setLoadOnStartup(1);
我如何获取这个XML文件并在上面的代码中完成同样的事情

<atmosphere-handlers>
    <atmosphere-handler context-root="/api" class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClassName"
                  value="com.sun.jersey.spi.spring.container.servlet.SpringServlet" />
    </atmosphere-handler>
</atmosphere-handlers>


我已经研究过向Atmosphere分配处理程序,但它需要一个我无法获得的
AtmosphereFramework
实例。

您可以通过以下操作添加AtmosphereHandler:

AtmosphereServlet s = new AtmosphereServlet();
AtmosphereFramework f = s.framework();

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

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

ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", s);
感谢您填写问题,顺便说一句,这将改进常见问题解答


--Jeanfrancois

棒极了,尽管它看起来像是
setServletClassName()
而不是
setServletClass()
,因为它已被弃用