我有一个在嵌入式码头中运行的球衣应用程序。我想将它转换为使用大气球衣来利用彗星功能,但我有点卡住了。非常感谢任何帮助。我的球衣代码使用配置了 ResourceConfig 的球衣 ServletContainer 来指定资源实例
ResourceConfig.registerInstances(resourceInstance);
new org.glassfish.jersey.servlet.ServletContainer(ResourceConfig);
我不知道如何使用相同的设置来处理气氛。我可以看到有一个 AtmosphereServlet。是否可以为其提供资源实例?
这就是目前设置球衣/码头的方式......
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
public class HelloWorldJerseyJetty {
// http://localhost:8080/resources/resource
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ResourceConfig config = new ResourceConfig();
config.registerInstances(new Resource("Hello World"));
org.glassfish.jersey.servlet.ServletContainer jerseyServlet = new org.glassfish.jersey.servlet.ServletContainer(config);
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(jerseyServlet), "/resources/*");
server.setHandler(handler);
server.start();
server.join();
}
@Path("resource")
public static class Resource {
private final String message;
public Resource(String message) {
this.message = message;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return message;
}
}
}
如何从球衣切换到 AtmosphereServlet 以及如何将其配置为使用实例?
ResourceConfig config = new ResourceConfig();
config.registerInstances(new Resource("Hello World"));
AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
atmosphereServlet.???
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(atmosphereServlet), "/resources/*");