使用jersey和maven开发RESTFul WebService

本文介绍了如何使用jersey框架和maven来开发RESTful WebService。jersey作为JSR311的开源实现,简化了Web服务的开发。通过maven配置jersey1.8、Junit4和jersey-json等依赖,创建Model类并使用@XmlRootElement注解,再利用jersey API构建服务,实现对数据库的CRUD操作。同时,文章还涉及了web.xml的配置,以及PUT和DELETE请求的客户端单元测试。最后,指出了访问其他资源的方法。
摘要由CSDN通过智能技术生成

jersey是一种RestFul Webservice开发框架,作为JSR311的开源实现,替代了原有的基于SOAP的Web服务。jersey提供了更为简洁的API,提供了更为简洁的开发模式。

在实际应用中,将基于maven构建开发环境,主要其他工具包括:jersey1.8、Junit4、jersey-json。使用webservice访问实现对数据库的CRUD模拟操作。

pom.xml核心片段:

<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.7</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-core</artifactId>
			<version>1.8</version>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-server</artifactId>
			<version>1.8</version>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-client</artifactId>
			<version>1.8</version>
		</dependency>
		<!-- Json -->
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-json</artifactId>
			<version>1.18</version>
		</dependency>
		<dependency>
			<groupId>com.owlike</groupId>
			<artifactId>genson</artifactId>
			<version>0.99</version>
		</dependency>

		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.14</version>
		</dependency>
		<dependency>
			<groupId>javax.ws.rs</groupId>
			<artifactId>jsr311-api</artifactId>
			<version
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值