转载请标明出处:http://blog.csdn.net/caizhh2009/article/details/6934845
这个不是重点:看不懂这个pom.xml没关系,也就是下载依赖包,打包,先继续往下看
@Path表示开启访问这个资源的路径
配置响应的listener和servlet无非就是初始resteasy的服务(先简单理解)
基于resteasy版本:2.2.1.GA
使用maven2.2.1作为构建和依赖管理工具
1.创建工程,配置pom.xml
mvn archetype:create -DgroupId=com.longtask.rest.easyrest -DartifactId=easyrest -DarchetypeArtifactId=maven-archetype-webapp
mvn eclipse:eclipse
注:使用m2eclipse插件可直接import- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>rest.resteasy</groupId>
- <artifactId>rest-resteay-demo</artifactId>
- <packaging>war</packaging>
- <version>1.0</version>
- <name>rest-resteay-demo Maven Webapp</name>
- <url>http://maven.apache.org</url>
- <repositories>
- <repository>
- <id>java.net</id>
- <url>http://download.java.net/maven/1</url>
- <layout>legacy</layout>
- </repository>
- <repository>
- <id>maven repo</id>
- <name>maven repo</name>
- <url>http://repo1.maven.org/maven2/</url>
- </repository>
- <!-- For resteasy -->
- <repository>
- <id>jboss</id>
- <name>jboss repo</name>
- <url>http://repository.jboss.org/nexus/content/groups/public/</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>2.2.1.GA</version>
- <!-- filter out unwanted jars -->
- <exclusions>
- <exclusion>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jettison-provider</artifactId>
- <version>2.2.1.GA</version>
- <exclusions>
- <exclusion>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.xml.stream</groupId>
- <artifactId>stax-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <finalName>rest-resteay-demo</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
2.编写jax-rs的服务类
- package resteasy.server;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- @Path(value = "echo")
- public class Echo {
- @GET
- @Path(value = "/{message}")
- public String echoService(@PathParam("message") String message)
- {
- return message;
- }
- }
@GET表示响应HTTP 的get方法
@PathParam表示引用URI中得参数
详细的注解可参考我下面的参考文档
3.web.xml的配置
- <!DOCTYPE web-app PUBLIC
- "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd" >
- <web-app>
- <context-param>
- <param-name>resteasy.resources</param-name>
- <param-value>resteasy.server.Echo</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>
3.打包部署到响应的servlet容器即可(如tomcat),然后访问http://localhost:8080/rest-resteay-demo/echo/hello,world,网页上出现hello,world则成功
hello,world可换成任意字符,同样也将返回响应的字符
注:如果不使用maven,则可以到resteasy官网下载响应jar包即可
下一章预告:阐述不同的方式用resteasy发布我们的restful webservice 服务,有问题可跟帖,一起讨论,共同进步
参考文献:
相关推荐
离线安装包,亲测可用
resteasy-reference-guide-en-US.pdf
resteasy入门级文档、如何使用Restful进行WebService的开发简介及相关RestEasy相关资源的链接
java运行依赖jar包
Resteasy JAX-RS 3.0.6-all.zip Resteasy JAX-RS最新官方zip包 包含文档资源包 webservice Restful 包含文档资源包
由jboss实现的resteasy框架,能够更好的支持restful服务,该资源为resteasy框架的工具包
该资源是java restful的应用框架resteasy---实现了jax-rs规范的一个demo,如有疑问请联系caizhh2009@gmail.com
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
java运行依赖jar包
离线安装包,亲测可用
resteasy-jaxrs-2.3.4.Final-all开发包
JBoss RESTEasy 是一个用来使用Java语言开发 RESTFul Web服务的框架。RESTEasy 项目是 JAX-RS 的一个实现,集成的一些亮点: * 不需要配置文件,只要把JARs文件放到类路径里面,添加 @Path 注解就可以了。 * 完全...
resteasy-jaxrs-2.3.2框架源码。希望您了解Resteasy框架有所帮助
RESTEasy:RESTEasy是JBoss的一个开源项目,提供各种框架帮助你构建RESTful Web Services和RESTful Java应用程序。它是JAX-RS规范的一个完整实现并通过JCP认证。 JAX-RS: 是一套用java实现REST服务的规范。(全名...
很实用的教程 有很多实例代码 基本都是代码
java运行依赖jar包
Resteasy发行版附带一个名为resteasy-jboss-modules-3.0.9.Final.zip的zip文件。 使用JBoss AS7发行版的modules /目录解压缩该文件。 这将覆盖那里的一些现有文件。 Swagger UI可以在这里访问: 任何改进的建议...
resteasy-netty-context-servlet 使用带有 resteasy 的 Netty 容器时注入 HttpServletRequest再现运行mvn clean package 运行mvn exec:java并在另一个命令行窗口中运行? curl -X POST ...
resteasy的官方源码 适合学习业务
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装