如果你只是依赖
org.glassfish.jersey.containers
jersey-container-jdk-http
2.2
然后,您可以启动服务器
JdkHttpServerFactory.createHttpServer(URI.create("http://localhost:8090/root"),
new MyApplication());
其中MyApplication扩展ResourceConfig以获取资源扫描.
@ApplicationPath("/")
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("...");
}
@GET
@Produces("text/plain")
public Response foo() {
return Response.ok("Hey, it's working!\n").build();
}
}
可能有更好的方法来控制服务器生命周期,但暂时还没有我这样做.