java – Jersey和Grizzly的Hello World(来自用户指南)
发布时间:2020-12-15 08:45:30 所属栏目:Java 来源:网络整理
导读:我正在查看 Jersey User Guide,并尝试使用Jersey Web服务和嵌入式Grizzly服务器设置Hello World示例. 我正在完成第1节“入门”.我已经在1.1节编译中得到了代码示例: // The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld")
我正在查看
Jersey User Guide,并尝试使用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"; } } 但接下来我将进入第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.wadln” + “Try out %shelloworldnHit 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个类. 解决方法
我认为答案是我需要包含
jersey-grizzly依赖项,然后我可以按照用户指南进行操作.
这未在用户指南提供的必需依赖项列表中指定:
感谢Ryan Stewart对类似问题的回答. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Java实现表单提交(支持多文件同时上传)
- java – OptimisticLockException当使用JPA merge()
- java – 在开发环境中,在tomcat中重新加载webapp是一种简单
- java – 如何知道从主类调用方法的次数?
- 自定义异常处理 – Java Web服务
- 阿里开源JDK dragonwell8在容器环境使用
- 一个Java人问:我为什么要学习Python?
- java – 如何在HttpSessionListener中获取HttpServletReque
- Java Spring MVC:没有为带HTTP的HTTP请求找到映射
- 如何安装jdk及安装MyEclipse的图文教程