RESTEasy 3.X Helloworld

來源:互聯網
上載者:User

  最近呢,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 -->

  第五步:啟動煙霧測試 (Smoke Test)

    http://ip:port/context/noon/whatyourwanna

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.