基于SSM+CXF构建的RESTFul webservice

开发环境:maven3.3.3、apache-tomcat-6.0.44、jdk1.6.0_13

开发技术:spring3.2.8、cxf2.7.12、mybatis3.2.8、druid1.0.11

项目截图:

项目源码:

一、配置文件

1、pom.xml

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.neusoft.icelake</groupId>
	<artifactId>restservice</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>restservice</name>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.6</java.version>
		<spring.version>3.2.8.RELEASE</spring.version>
		<servlet-api.version>2.5</servlet-api.version>
		<slf4j.version>1.7.5</slf4j.version>
		<cxf.version>2.7.12</cxf.version>
		<jackson.version>2.1.4</jackson.version>

		<mybatis.version>3.2.8</mybatis.version>
		<mybatisspring.version>1.2.2</mybatisspring.version>
		<druid.version>1.0.11</druid.version>
	</properties>

	<dependencies>
		<!-- spring begin -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc-portlet</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- spring end -->

		<!-- @Inject begin -->
		<dependency>
			<groupId>javax.inject</groupId>
			<artifactId>javax.inject</artifactId>
			<version>1</version>
		</dependency>
		<!-- @Inject end -->

		<!-- servlet begin -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>${servlet-api.version}</version>
		</dependency>
		<!-- servlet end -->

		<!-- cxf begin -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-rs-extension-providers</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jettison</groupId>
			<artifactId>jettison</artifactId>
			<version>1.3.2</version>
		</dependency>
		<dependency>
			<groupId>javax.ws.rs</groupId>
			<artifactId>jsr311-api</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!-- cxf end -->

		<!-- JSON begin -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.module</groupId>
			<artifactId>jackson-module-jaxb-annotations</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.jaxrs</groupId>
			<artifactId>jackson-jaxrs-json-provider</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>1.9.0</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-core-asl</artifactId>
			<version>1.9.0</version>
		</dependency>
		<!-- JSON end -->

		<!-- MyBatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>${mybatisspring.version}</version>
		</dependency>
		<!-- AOP begin -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.7.4</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.7.4</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>3.1</version>
		</dependency>
		<!-- AOP end -->
		<!-- jdbc driver -->
		<dependency>
			<groupId>localrep.sybase</groupId>
			<artifactId>jconn</artifactId>
			<version>2.0</version>
		</dependency>
		<!-- connection pool -->
		<dependency>
		     <groupId>com.alibaba</groupId>
		     <artifactId>druid</artifactId>
		     <version>${druid.version}</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- compiler插件, 设定JDK版本 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.0</version>
				<configuration>
					<source>${java-version}</source>
					<target>${java-version}</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<!-- PROGRAMER INFO -->
	<organization>
		<name>Neusoft</name>
		<url>http://www.neusoft.com</url>
	</organization>
</project>

2、spring配置文件applicationContext-server.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

	<context:component-scan base-package="com.neusoft.icelake" />

	<import resource="classpath*:META-INF/cxf/cxf.xml" />
	<import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath*:META-INF/cxf/cxf-servlet.xml" />

	<jaxrs:server id="restServiceContainer" address="/rest">
		<jaxrs:providers>
			<ref bean="jacksonProvider" />
		</jaxrs:providers>
		<jaxrs:extensionMappings>
			<entry key="json" value="application/json" />
			<entry key="xml" value="application/xml" />
		</jaxrs:extensionMappings>

		<jaxrs:serviceBeans>
			<ref bean="wholeQuantityService" />
		</jaxrs:serviceBeans>

		<jaxrs:inInterceptors>
			<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
		</jaxrs:inInterceptors>
		<jaxrs:outInterceptors>
			<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
		</jaxrs:outInterceptors>
	</jaxrs:server>

	<bean id="jacksonObjectMapper"
		class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"></bean>
	<bean id="jacksonProvider"
		class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
		<property name="mapper" ref="jacksonObjectMapper" />
	</bean>

</beans>

3、spring配置文件applicationContext-mybatis.xml

<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<context:property-placeholder ignore-unresolvable="true" location="classpath:config.properties" />

	<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="initialSize" value="0" />
		<property name="maxActive" value="20" />
		<property name="minIdle" value="0" />
		<property name="maxWait" value="60000" />
		<property name="validationQuery" value="${jdbc.testSql}" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="testWhileIdle" value="true" />
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<property name="minEvictableIdleTimeMillis" value="25200000" />
		<property name="removeAbandoned" value="true" />
		<property name="removeAbandonedTimeout" value="1800" />
		<property name="logAbandoned" value="true" />
		<property name="filters" value="mergeStat" />
	</bean>

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath:com/neusoft/icelake/mappers/**/*.xml" />
	</bean>
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.neusoft.icelake" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>

	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="append*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="modify*" propagation="REQUIRED" />
			<tx:method name="edit*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="remove*" propagation="REQUIRED" />
			<tx:method name="repair" propagation="REQUIRED" />
			<tx:method name="delAndRepair" propagation="REQUIRED" />

			<tx:method name="get*" propagation="SUPPORTS" />
			<tx:method name="find*" propagation="SUPPORTS" />
			<tx:method name="load*" propagation="SUPPORTS" />
			<tx:method name="search*" propagation="SUPPORTS" />
			<tx:method name="datagrid*" propagation="SUPPORTS" />

			<tx:method name="*" propagation="SUPPORTS" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="transactionPointcut" expression="execution(* com.neusoft.icelake..*impl.*(..))" />
		<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
	</aop:config>

</beans>

4、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>restservice</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:/spring-context*.xml</param-value>
	</context-param>
	<listener>
		<description>spring listener</description>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>CXFServlet</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
	<servlet>
		<servlet-name>DruidStatView</servlet-name>
		<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>DruidStatView</servlet-name>
		<url-pattern>/druid/*</url-pattern>
	</servlet-mapping>

	<filter>
		<filter-name>DruidWebStatFilter</filter-name>
		<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
		<init-param>
			<param-name>exclusions</param-name>
			<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>DruidWebStatFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

二、Java代码

1、entity类(Org.java、Orgs.java)

package com.neusoft.icelake.modules.standard.entity;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "SapOrg")
public class Org implements Serializable {

    private static final long serialVersionUID = 7446548875479453298L;

    private String parent_id;

    private String parent_desc;

    private String child_id;

    private String child_desc;

    private String child_short;

    private String org_sort;

    public String getParent_id() {
        return parent_id;
    }

    public void setParent_id(String parent_id) {
        this.parent_id = parent_id;
    }

    public String getParent_desc() {
        return parent_desc;
    }

    public void setParent_desc(String parent_desc) {
        this.parent_desc = parent_desc;
    }

    public String getChild_id() {
        return child_id;
    }

    public void setChild_id(String child_id) {
        this.child_id = child_id;
    }

    public String getChild_desc() {
        return child_desc;
    }

    public void setChild_desc(String child_desc) {
        this.child_desc = child_desc;
    }

    public String getChild_short() {
        return child_short;
    }

    public void setChild_short(String child_short) {
        this.child_short = child_short;
    }

    public String getOrg_sort() {
        return org_sort;
    }

    public void setOrg_sort(String org_sort) {
        this.org_sort = org_sort;
    }

    @Override
    public String toString() {
        return "Org [parent_id=" + parent_id + ", parent_desc=" + parent_desc + ", child_id=" + child_id
                + ", child_desc=" + child_desc + ", child_short=" + child_short + ", org_sort=" + org_sort
                + "]";
    }
}
package com.neusoft.icelake.modules.standard.entity;

import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "SapOrgs")
public class Orgs {
    private List<Org> list;

    private Org[] array;

    private Map<String, Org> map;

    public List<Org> getList() {
        return list;
    }

    public void setList(List<Org> list) {
        this.list = list;
    }

    public Org[] getArray() {
        return array;
    }

    public void setArray(Org[] array) {
        this.array = array;
    }

    public Map<String, Org> getMap() {
        return map;
    }

    public void setMap(Map<String, Org> map) {
        this.map = map;
    }
}

2、Mybatis mapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.neusoft.icelake.modules.standard.dao.IWholeQuantityDao">
	<resultMap id="EmpResultMap"
		type="com.neusoft.icelake.modules.standard.entity.Emp">
		<id column="accno" property="accno" jdbcType="VARCHAR" />
		<result column="truename" property="truename" jdbcType="VARCHAR" />
		<result column="gender" property="gender" jdbcType="VARCHAR" />
		<result column="office_mail" property="office_mail" jdbcType="VARCHAR" />
		<result column="title" property="title" jdbcType="VARCHAR" />
		<result column="dp_id" property="dp_id" jdbcType="VARCHAR" />
		<result column="person_sort" property="person_sort" jdbcType="VARCHAR" />
		<result column="del_tag" property="del_tag" jdbcType="VARCHAR" />
	</resultMap>
	<resultMap id="OrgResultMap"
		type="com.neusoft.icelake.modules.standard.entity.Org">
		<id column="child_id" property="child_id" jdbcType="VARCHAR" />
		<result column="child_desc" property="child_desc" jdbcType="VARCHAR" />
		<result column="child_short" property="child_short" jdbcType="VARCHAR" />
		<result column="parent_id" property="parent_id" jdbcType="VARCHAR" />
		<result column="parent_desc" property="parent_desc" jdbcType="VARCHAR" />
		<result column="org_sort" property="org_sort" jdbcType="VARCHAR" />
	</resultMap>
	<sql id="Emp_Column_List">
		accno, truename, gender, office_mail, title, dp_id,
		person_sort, del_tag
	</sql>
	<sql id="Org_Column_List">
		parent_id, parent_desc, child_id, child_desc, child_short,
		org_sort
	</sql>
	<select id="getEmpAll" resultMap="EmpResultMap">
		select
		<include refid="Emp_Column_List" />
		from v_person
	</select>
	<select id="getOrgAll" resultMap="OrgResultMap">
		select
		<include refid="Org_Column_List" />
		from v_sap_org_node
	</select>
</mapper>

3、接口的服务类

package com.neusoft.icelake.modules.standard.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.neusoft.icelake.modules.standard.entity.Emps;
import com.neusoft.icelake.modules.standard.entity.Orgs;

@Path("/wq")
public interface IWholeQuantityService {

    @GET
    @Path("/orglist")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Orgs getOrgList();

    @GET
    @Path("/emplist")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Emps getEmpList();
}

4、接口的实现类

package com.neusoft.icelake.modules.standard.service.impl;

import java.util.List;

import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;

import com.neusoft.icelake.modules.standard.dao.IWholeQuantityDao;
import com.neusoft.icelake.modules.standard.entity.Emp;
import com.neusoft.icelake.modules.standard.entity.Emps;
import com.neusoft.icelake.modules.standard.entity.Org;
import com.neusoft.icelake.modules.standard.entity.Orgs;
import com.neusoft.icelake.modules.standard.service.IWholeQuantityService;

@Named("wholeQuantityService")
public class WholeQuantityServiceImpl implements IWholeQuantityService {
    private IWholeQuantityDao wholeQuantityDao;

    public IWholeQuantityDao getWholeQuantityDao() {
        return wholeQuantityDao;
    }

    @Autowired
    public void setWholeQuantityDao(IWholeQuantityDao wholeQuantityDao) {
        this.wholeQuantityDao = wholeQuantityDao;
    }

    @Override
    public Orgs getOrgList() {
        Orgs orgs = new Orgs();
        List<Org> orglist = wholeQuantityDao.getOrgAll();
        orgs.setList(orglist);
        return orgs;
    }

    @Override
    public Emps getEmpList() {
        Emps emps = new Emps();
        List<Emp> emplist = wholeQuantityDao.getEmpAll();
        emps.setList(emplist);
        return emps;
    }
}

运行项目:

打开浏览器,在地址栏输入:http://localhost:8080/restservice/rest?_wadl

可以看到我们发布的webservice的接口描述文件(wadl描述):

访问http://localhost:8080/restservice/rest/wq/orglist?_type=json,返回Json结果,

或者http://localhost:8080/restservice/rest/wq/orglist?_type=xml,返回XML

源码下载:http://download.csdn.net/detail/iamlake/9498889

时间: 2024-10-07 22:05:08

基于SSM+CXF构建的RESTFul webservice的相关文章

spring+cxf+hibernate&#160;&#160;发布restful&#160;WebService服务

项目目录结构 项目下载路径: http://pan.baidu.com/s/1o6H06LW   (如果项目路径实效,可以qq找我,下面有我qq) 1.we b.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.c

MAVEN,SPRING,CXF构建REST风格WebService

1.IDEA简历Maven模板webapp项目 2.Pom文件添加依赖项 <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-v

开发基于CXF的 RESTful WebService web 项目 webservice发布

配置步骤 开发基于CXF的 RESTful WebService 1.创建Web项目并导入CXF的jar 2.在Web.xml中配置 CXFServlet <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-

SpringBoot | 第三十四章:CXF构建WebService服务

前言 上一章节,讲解了如何使用Spring-WS构建WebService服务.其实,创建WebService的方式有很多的,今天来看看如何使用apache cxf来构建及调用WebService服务. 前言 一点知识 何为Apache-CXF 关于JAX-WS规范 常用注解介绍 SpringBoot整合CXF实例 服务端构建 客户端调用 异常捕获 自定义拦截器 服务端拦截器 客户端拦截器 参考资料 总结 最后 老生常谈 一点知识 何为Apache-CXF Apache CXF是一个开源的Serv

CXF发布支持ajax跨域访问的restful webservice

用apache cxf构建了一个玩具型restful webservice,内嵌jetty,加上gradle,发布无比轻松. apply plugin: 'java' apply plugin: 'application' repositories { maven { url "http://maven.oschina.net/content/groups/public" } } [compileJava,compileTestJava,javadoc]*.options*.encod

cxf构建webservice的两种方式

一.简介 对于基于soap传输协议的webservice有两种开发模式,代码优先和契约优先的模式.代码优先的模式是通过编写服务器端的代码,使用代码生成wsdl:契约优先模式首先编写wsdl,再通过wsdl生成服务器端的代码.对于代码优先的模式在使用cxf构建webservice 一文中已经做出介绍,这里主要介绍第二种方式. 二.wsdl文件结束 一般wsdl文件结构如下: <?xml version='1.0' encoding='UTF-8'?> <wsdl:definitions x

在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用

在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用 RESTful Web 服务简介 REST 在 2000 年由 Roy Fielding 在博士论文中提出,他是 HTTP 规范 1.0 和 1.1 版的首席作者之一. REST 中最重要的概念是资源(resources),使用全球 ID(通常使用 URI)标识.客户端应用程序使用 HTTP 方法(GET/ POST/ PUT/ DELETE)操作资源或资源集.RESTful Web 服务是使用 H

Java基于ssm框架的restful应用开发

Java基于ssm框架的restful应用开发 好几年都没写过java的应用了,这里记录下使用java ssm框架.jwt如何进行rest应用开发,文中会涉及到全局异常拦截处理.jwt校验.token拦截器等内容. 1.jwt工具类 直接贴代码了,主要包括jwt的sign.verify.decode三个方法,具体实现如下: package com.isoft.util; import java.util.Date; import com.auth0.jwt.JWT; import com.aut

SOAP webserivce 和 RESTful webservice 对比及区别

简单对象访问协议(Simple Object Access Protocol,SOAP)是一种基于 XML 的协议,可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议(HTTP),简单邮件传输协议(SMTP),多用途网际邮件扩充协议(MIME),基于"通用"传输协议是 SOAP的一个优点.它还支持从消息系统到远程过程调用(Remote Procedure Call,RPC)等大量的应用程序.SOAP提供了一系列的标准,如WSRM(WS-Reliable Messaging)形