[英]How to enable CDI inject in web service (jaxrs/jersey) on java se running grizzly?
[英]How to run Jersey with the built in web server from Java SE 6?
我不想使用Tomcat,Jetty或Java EE 6容器来提供REST服务,而是使用内置的Web服务器。
确保在类路径中有Jersey的jersey-server.jar
,然后它就像下面这样简单:
HttpServer server = HttpServerFactory.create("http://localhost:9998/");
server.start();
选择您想要使用的任何端口。
对于Jersey 2.x,您需要在类路径中使用jersey-container-jdk-http 。 如果您正在使用maven,请将其添加到您的pom.xml
:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jdk-http</artifactId>
<version>2.9.1</version>
</dependency>
要启动服务器,请使用:
URI baseUri = UriBuilder.fromUri("http://localhost/").port(10000).build();
ResourceConfig resourceConfig=new ResourceConfig(WebService.class);
HttpServer httpServer=JdkHttpServerFactory.createHttpServer(baseUri, resourceConfig,true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.