java实现REST方式的webService

此文章是基于

  搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台

 

一. 简介

    WebService有两种方式,一是SOAP方式,二是REST方式。SOAP是基于XML的交互,WSDL也是一个XML文档,

  可以使用WSDL作为SOAP的描述文件;REST是基于HTTP协议的交互,支持JSON、XML等交互,不需要WSDL。

 

二. 准备工作

  1. 点击此下载相关文件,并把文件放到 ims 工程对应的文件夹下

 

三. jar包介绍

  1. 点击此下载 apache-cxf-3.0.3,并在 lib 文件夹下得到:

commons-codec-1.9.jar
cxf-core-3.0.3.jar
cxf-rt-frontend-jaxrs-3.0.3.jar
cxf-rt-transports-http-3.0.3.jar
javax.ws.rs-api-2.0.1.jar

  2. commons-httpclient-3.1.jar

 

四. 相关程序代码

  1. applicationInterface.xml:spring配置文件


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
        
    <!-- cxf发布rest服务 -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>   
    <!-- 这里是cxf2.x版本的配置,3.0没有了要去掉 --> 
    <!-- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> -->
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    
    <bean id="rec
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值