Tom*_*sky 3 java web-services jersey grizzly
我正在查看Jersey用户指南,并尝试使用Jersey Web服务和嵌入式Grizzly服务器设置Hello World示例.
我正在完成第1节"入门".我已经在1.1节编译中得到了代码示例:
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String getClichedMessage() {
// Return some cliched textual content
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
但接下来我将进入第1.2节"部署根资源",这是我应该设置嵌入式Grizzly Web服务器以测试我的资源:
public class Main {
public static void main(String[] args) throws IOException {
final String baseUri = "http://localhost:9998/";
final Map<String, String> initParams =
new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages",
"com.sun.jersey.samples.helloworld.resources");
System.out.println("Starting grizzly...");
SelectorThread threadSelector =
GrizzlyWebContainerFactory.create(baseUri, initParams);
System.out.println(String.format(
"Jersey app started with WADL available at %sapplication.wadl\n” +
“Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri));
System.in.read();
threadSelector.stopEndpoint();
System.exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,似乎这个用户指南暂时没有更新,并且该类GrizzlyWebContainerFactory不再存在!
我正在使用Jersery v 1.10和Grizzly v 1.9.41.
有人可以帮我重新创建这个例子吗?我知道我可以在容器中运行Web服务,我有兴趣通过最简单的嵌入式服务器设置运行它,在我的项目中不需要额外的资源(web.xml等),只需要2个类.
我认为答案是我需要包含泽西 - 灰熊依赖,然后我可以按照用户指南进行操作.
这是不是在所需的相关用户指南提供的列表中指定:
非专业开发人员要求:
grizzly-servlet-webserver.jar,jersey-server.jar,jersey-core.jar,jsr311-api.jar,asm.jar
感谢 Ryan Stewart对类似问题的回答.
| 归档时间: |
|
| 查看次数: |
9870 次 |
| 最近记录: |