RestEasy 3.x 系列之一:Hello world

RestEasy 3.x改了不少,走了好多弯路才终于搞出来,做做笔记,陆续发布……

tomcat-7.0.50

java version "1.7.0_51"

myeclipse 10

1、新建web 项目RestEasy_01_Hello_world,注意一定要java ee 1.6以上

2、创建包com.tutu.test

创建类Noon.java

package com.tutu.test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;


//http://localhost:8080/RestEasy_01_Hello_world/noon/Hello world

@Path("noon")
public class Noon
{

   @GET
   @Path("{name}")
   public String hello(@PathParam("name") final String name) {
      return name;
   }
}

3、配置web.xml

<web-app>
    
<!--  这个经验证不行  
    <context-param>
		<param-name>resteasy.scan</param-name>
		<param-value>true</param-value>
	</context-param>
 -->   
 
 <!--  重要resteasy.resources  -->  
    <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.tutu.test.Noon</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>/*</url-pattern>
    </servlet-mapping>
 
</web-app>  

4、发布测试,如果上面红色的地方错误或者context-param没有,将发布无效:

http://localhost:8080/RestEasy_01_Hello_world/noon/Hello world

ok

5、源码下载

RestEasy_01_Hello_World.zip

你可能感兴趣的:(RestEasy 3.x 系列之一:Hello world)