我正在查看Jersey User Guide并尝试使用Jersey Web服务和嵌入式Grizzly服务器设置Hello World示例。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";
}
}
但后来我得到第1.2节“部署根资源”,这就是我应该设置嵌入灰熊网服务器与测试我的资源:
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);
}
}
的问题是,它似乎本用户指南还没有在一段时间更新,类GrizzlyWebContainerFactory
不再存在!
我使用Jersery v 1.10和Grizzly v 1.9.41。
有人可以帮我重新创建这个例子吗?我知道我可以在一个容器中运行Web服务,我有兴趣通过最简单的嵌入式服务器设置运行它,而不需要额外的资源(web.xml等)在我的项目中,只有2个类。
感谢您的收获。我们会修好的。 –
问题已提交:http://java.net/jira/browse/JERSEY-840 –
太棒了!我喜欢用它来观看这样的事情!希望能够帮助其他泽西新手避免混淆。 –