最近呢,RESTEasy也升级了。升到了3.X。
官网:http://www.jboss.org/resteasy
集成使用也非常简单(相比SOAP而言)
第一步:下载jar包
resteasy是托管在sourceforge网站。所以下载地址为:http://sourceforge.net/projects/resteasy/files/Resteasy%20JAX-RS/
这里选择下载3.x final
第二步:拷贝到工程classpath目录下
把lib都拷过去
resteasy-jaxrs-3.x.jar 这个是核心包
第三步:编写jax-rs风格的服务类
Noon.java(与Jersey服务类无异)
package com.linpeng.ws.rest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/noon") public class Noon{ @GET @Path("/{param}") @Produces(MediaType.TEXT_PLAIN) public String getMsg(@PathParam("param") String name) { String msg = "Rest say: good noon " + name; return msg; } }
第四步:配置web.xml
<!-- resteasy begin --> <!-- Auto scan REST service --> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <!-- this need same with resteasy servlet url-pattern --> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/resteasy</param-value> </context-param> <listener> <listener-class> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap </listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher </servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/resteasy/*</url-pattern> </servlet-mapping> <!-- resteasy end -->
第五步:启动冒烟测试
http://ip:port/context/noon/whatyourwanna