对WebService的系统研究, 七种方式实现!

 注册CSDN已有很长的一段时间,也包括其它很多论坛、社区,一直都是默默地看着别人的文章,自己却不曾写过。一方面是觉得要写出优秀的原创博客需要及其精湛的技术内功,自己还有欠缺;另一方面是自己一直在系统地钻研Java、OC、JS、H5、Python、PHP这几门语言,弥补之前的泛泛而学,时间不是很宽裕。从今天开始我愿把我在技术之路上遇到的坎坷与心得和大家分享,这将是我的第一篇原创博客!
 文章主要内容如题所言,下面让我们开始吧!


1. 通过JDK自定义服务端并接收服务, 用JDK命令生成客户端, 并通过JDK的方式调用自己发布的服务接口, 我的JDK版本是1.8;
   客户端: client1_jdk;
   服务端: server1_jdk;
   对应命令: wsimport -p client1_jdk -s /Users/hejinghui/eclipse-workspace/day20_webService_cxf_spring_client_practice/src http://127.0.0.1:8090/weather?wsdl

    客户端测试代码:
    Client1_jdk_test.java
package clientTest;

import client1_jdk.WeatherInterface;
import client1_jdk.WeatherInterfaceImplService;

public class Client1_jdk_test {
	public static void main(String[] args) {
		WeatherInterfaceImplService weatherInterfaceImpl = new WeatherInterfaceImplService();
		WeatherInterface weatherInterface = weatherInterfaceImpl.getPort(WeatherInterface.class);
		String weather = weatherInterface.queryWeather("北京");
		System.out.println(weather);
	}
}
服务端代码:
 WeatherInterface.java

package server1_jdk;

import javax.jws.WebService;

@WebService
public interface WeatherInterface {
	
	public  String queryWeather(String cityName);
}

    WeatherInterfaceImpl.java

package server1_jdk;

public class WeatherInterfaceImpl implements WeatherInterface {

	@Override
	public String queryWeather(String cityName) {
		
		if ("北京".equals(cityName)) {
			return "大雪";
		} else {
			return "晴天";
		}
	}
}

    WeatherPublish.java

package server1_jdk;

import javax.xml.ws.Endpoint;

public class WeatherPublish {

	public static void main(String[] args) {
		
		Endpoint.publish("http://127.0.0.1:8090/weather", new WeatherInterfaceImpl());
		
		System.out.println("发布成功");
	}
}


2. 通过JDK接收他人服务, 用JDK命令生成客户端, 调用他人发布的服务端接口;
   客户端: client2_jdk;
   服务端: 他人的服务;
   对应命令: wsimport -p client2_jdk -s /Users/hejinghui/eclipse-workspace/day20_webService_cxf_spring_client_practice/src http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
   
    客户端测试代码:
    Client2_jdk_test.java
package clientTest;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import client2_jdk.MobileCodeWSSoap;

public class Client2_jdk_test {
	public static void main(String[] args) throws MalformedURLException {
		
		// 1.创建服务视图
		/**
		 * 参数1: wsdl地址 
		 * 参数2: 服务名称
		 */
		URL url = new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl");
		/**
		 * 参数1: 命名空间地址 targetNamespace="http://WebXml.com.cn/" 
		 * 参数2: 服务视图名称 ,service的name值
		 */
		QName qName = new QName("http://WebXml.com.cn/", "MobileCodeWS");
		Service service = Service.create(url, qName);
		
		// 2.获取服务实现类
		MobileCodeWSSoap mobileCodeWSSoap = service.getPort(MobileCodeWSSoap.class);
		
		// 3.调用查询方法
		String result = mobileCodeWSSoap.getMobileCodeInfo("18888888888", "");
		System.out.println(result);
	}
}
3. 通过HttpURLConnection调用他人发布的服务端接口;

   客户端: client3_HttpURLConnection_jdk;
   服务端: 他人的服务;
    客户端测试代码:
    client3_HttpURLConnection_jdk_test.java

package client3_HttpURLConnection_jdk;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;

public class client3_HttpURLConnection_jdk_test {

	public static void main(String[] args) throws DocumentException, IOException {
		// 1. 创建服务地址, 不是WSDL地址
		URL url = new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx");
		// 2. 打开一个通向服务地址的连接
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		// 3. 设置参数
		// 3.1 发送方式设置: POST必须大写
		connection.setRequestMethod("POST");
		// 3.2 设置数据格式: content-type
		connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
		// 3.3 设置输入输出, 因为默认新创建的connection没有读写权限
		connection.setDoOutput(true);
		connection.setDoOutput(true);
		// 4. 组织SOAP数据, 发送请求
		String aopxml = getXML("18688888888");
		OutputStream outputStream = connection.getOutputStream();
		outputStream.write(aopxml.getBytes());
		// 5. 接收服务端响应, 打印
		if (200 == connection.getResponseCode()) {

			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);

			StringBuilder sb = new StringBuilder();
			String temp = null;
			while (null != (temp = br.readLine())) {
				sb.append(temp);
			}
			Document document = DocumentHelper.parseText(sb.toString());
			parseDocument(document);
			is.close();
			isr.close();
			br.close();
		}
		outputStream.close();
	}

	public static void parseDocument(Document document) {
		parseDocument(document.getRootElement());
	}

	public static void parseDocument(Element element) {
		for (int i = 0, size = element.nodeCount(); i < size; i++) {
			Node node = element.node(i);
			if (node instanceof Element) {
				parseDocument((Element) node);
			} else {
				// do something....

				if (node.getNodeTypeName().equals("Text")) {
					System.out.println(node.getText());
				}
			}
		}
	}

	private static String getXML(String string) {

		String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n" + "  <soap:Body>\r\n"
				+ "    <getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\">\r\n" + "      <mobileCode>" + string + "</mobileCode>\r\n" + "      <userID></userID>\r\n" + "    </getMobileCodeInfo>\r\n" + "  </soap:Body>\r\n" + "</soap:Envelope>";
		return xml;
	}
}

4. 通过CXF框架发布并接收服务, 用CXF框架命令生成客户端, 我用的CXF版本是3.2.1;
CXF下载地址:点击打开链接, 下载完成后把apache-cxf-3.2.1文件夹下lib中的所有jar引入工程, 如果工程报错误:Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springcxf-server]],则需要删除如下四个jar包:
   cxf-services-ws-discovery-api-3.2.1.jar
 cxf-services-ws-discovery-service-3.2.1.jar
  cxf-services-wsn-api-3.2.1.jar
  cxf-services-wsn-core-3.2.1.jar


客户端: client4_cxf;

服务端: server4_cxf;
 对应命令: wsdl2java -p client4_cxf -d /Users/hejinghui/eclipse-workspace/day20_webService_cxf_spring_client_practice/src http://127.0.0.1:8090/weather?wsdl
   在执行这个命令的时候有一些小插曲, 竟然报如下错误: 
   $ wsdl2java -p client4_cxf -d /Users/hejinghui/eclipse-workspace/day20_webService_cxf_spring_client_practice/src http://127.0.0.1:8090/weather?wsdl
   /Users/hejinghui/Documents/apache-cxf-3.2.1/bin/wsdl2java: line 81: /System/Library/Frameworks/JavaVM.framework/Home/bin/java: No such file or directory
   这很可能是JAVA_HOME找不到呀, 突然想到本人当初Mac上安装的是Java应用而不是下载的JDK, 这就恰巧避免了配置JAVA_HOME, 最终还是自己挖的坑自己填呐! 立马vim ~/.bash_profile, 果然没有, 首先宽慰自己淡定, 紧接着来一波命令:
   export JAVA_HOME=$(/usr/libexec/java_home)
   export PATH=$JAVA_HOME/bin:$PATH
   export CLASS_PATH=$JAVA_HOME/lib
   保存并退出,然后执行source ~/.bash_profile使环境变量生效, 输入echo $JAVA_HOME验证一下, 成功! 

    客户端测试代码:

    Client4_cxf_test.java

package clientTest;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import client4_cxf.WeatherInterface;

public class Client4_cxf_test {

	public static void main(String[] args) {
		
		JaxWsProxyFactoryBean factoryBean =new JaxWsProxyFactoryBean();
		// 设置服务接口
		factoryBean.setServiceClass(WeatherInterface.class);
		// 设置服务地址
		factoryBean.setAddress("http://127.0.0.1:8090/weather");
		// 获取服务接口实例
		WeatherInterface weatherInterface =factoryBean.create(WeatherInterface.class);
		// 调用查询方法
		String string = weatherInterface.queryWeather("北京");
		System.out.println(string);
	}
}
    服务端代码:

    WeatherInterface.java

package server4_cxf;

import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;

@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public interface WeatherInterface {
	public String queryWeather(String cityName);
}

   WeatherInterfaceImpl.java

package server4_cxf;

public class WeatherInterfaceImpl implements WeatherInterface {

	@Override
	public String queryWeather(String cityName) {
		if ("北京".equals(cityName)) {
			return "干旱";
		} else {
			return "晴天";
		}
	}
}

    WeatherServicePublish.java

package server4_cxf;

import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class WeatherServicePublish {
	
	// 用JaxWsServerFactoryBean发布服务,设置3个参数,1.服务接口;2.服务实现类;3.服务地址;
	public static void main(String[] args) {
		
		JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
		// 设置服务接口
		factoryBean.setServiceClass(WeatherInterface.class);
		// 设置服务实现类
		factoryBean.setServiceBean(new WeatherInterfaceImpl());
		// 设置服务地址
		factoryBean.setAddress("http://127.0.0.1:8090/weather");
		// 发布
		factoryBean.create();
		
		System.out.println("发布成功");
	}
}

5. 通过CXF+Spring整合发布SOAP的服务,用CXF框架命令生成客户端;
   客户端: client5_cxf_spring_soap;
   服务端: server5_cxf_spring_soap;
   对应命令: wsdl2java -p client5_cxf_spring_soap -d /Users/hejinghui/eclipse-workspace/day20_webService_cxf_spring_client_practice/src http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/weather?wsdl

    客户端测试代码:

    Client5_cxf_spring_soap_test.java

package clientTest;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import client5_cxf_spring_soap.WeatherInterface;

public class Client5_cxf_spring_soap_test {

	public static void main(String[] args) {
		
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
		WeatherInterface weatherInterface = (WeatherInterface) context.getBean("client5_cxf_spring_soap");
		String info = weatherInterface.queryWeather("北京");
		System.out.println(info);
	}
}
 服务端代码:

    WeatherInterface.java

package server5_cxf_spring_soap;

import javax.jws.WebService;

@WebService
public interface WeatherInterface {
	
	public  String queryWeather(String cityName);
}

WeatherInterfaceImpl.java

package server5_cxf_spring_soap;

public class WeatherInterfaceImpl implements WeatherInterface {

	@Override
	public String queryWeather(String cityName) {
		
		if ("北京".equals(cityName)) {
			return "北京:大雪沙尘暴";
		} else {
			return "其他地方:冰雹";
		}
	}
}

6. 通过CXF框架发布RESTful风格的服务;
   客户端: client6_cxf_RESTful
   服务端: server6_cxf_RESTful
   测试服务: 服务端指定返回的数据类型包括json时才能加"?_type=json", 若加了则返回数据类型为json, 不加为xml
   查询单个学生: http://localhost:9999/hjh/student/query/1
   查询多个学生: http://localhost:9999/hjh/student/queryList/9527?_type=json

    客户端测试代码:
 Client6_cxf_RESTful_test.java

package client6_cxf_RESTful;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Client6_cxf_RESTful_test {

	public static void main(String[] args) throws Exception {
		
		// 第一步: 创建服务地址,不是WSDL地址
		URL url = new URL("http://localhost:9999/hjh/student/queryList/9527?_type=json");
		// 第二步: 打开一个通向服务地址的连接
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		// 第三步: 设置参数
		// 3.1 发送方式设置: GET必须大写(如果是POST, 也必须大写)
		connection.setRequestMethod("GET");
		// Post 请求不能使用缓存
		connection.setUseCaches(false);
		connection.setInstanceFollowRedirects(true);
		// 3.2 设置数据格式: content-type
		// 3.3 设置输入输出, 因为默认新创建的connection没有读写权限
		connection.setDoInput(true);
		connection.setDoOutput(true);
		// 第五步: 接收服务端响应,打印
		int responseCode = connection.getResponseCode();
		// 表示服务端响应成功
		System.out.println("responseCode==" + responseCode);
		if (200 == responseCode) {
			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);

			StringBuilder sb = new StringBuilder();
			String temp = null;
			while (null != (temp = br.readLine())) {
				sb.append(temp);
			}
			System.out.println(sb.toString());
			// dom4j解析返回数据...此处省略
			is.close();
			isr.close();
			br.close();
		}
	}
}
 
    服务端代码:

    StudentInterface.java
package server6_cxf_RESTful;

import java.util.List;
import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import model.Student;

@WebService
@Path("/student") // @Path("/student")就是将请求路径中的“/student”映射到接口上
public interface StudentInterface {

	@GET // 指定请求方式, 如果服务端发布的时候指定的是GET(POST), 那么客户端访问时必须使用GET(POST)
	@Produces(MediaType.APPLICATION_XML) // 指定服务数据类型为xml格式, 此时服务地址后不可加?_type=json
	@Path("/query/{id}") // @Path("/query/{id}")就是将"/query"映射到方法上, "{id}"映射到参数上, 多个参数, 以“/”隔开, 放到“{}”中
	// 根据id查询单个学生
	public Student queryStuById(@PathParam("id") Integer id);

	@GET
	@Produces({ MediaType.APPLICATION_XML, "application/json;charset=utf-8" }) // 可以是xml或json格式, 默认是xml
	@Path("/queryList/{classroom}")
	// 查询多个学生
	public List<Student> queryStudentList(@PathParam("classroom") String classroom);
}
     StudentInterfaceImpl.java

package server6_cxf_RESTful;

import java.util.ArrayList;
import java.util.List;

import model.Student;

public class StudentInterfaceImpl implements StudentInterface {

	@Override
	public Student queryStuById(Integer id) {
		Student student = new Student();
		student.setId(id);
		student.setName("张三");
		student.setAge(20);
		return student;
	}

	@Override
	public List<Student> queryStudentList(String classroom) {
		Student student1 = new Student();
		student1.setId(110);
		student1.setName("张三");
		student1.setAge(19);
		student1.setClassroom(classroom);
		
		Student student2 = new Student();
		student2.setId(120);
		student2.setName("李四");
		student2.setAge(23);
		student2.setClassroom(classroom);
		
		List<Student> list = new ArrayList<Student>();
		list.add(student1);
		list.add(student2);
		return list;
	}

}

    StudentServicePublish.java

package server6_cxf_RESTful;

import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;

public class StudentServicePublish {

	public static void main(String[] args) {

		/**
		 * JaxWsServerFactoryBean发布普通服务
	     * JAXRSServerFactoryBean发布RESTful的服务
		 */
		JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
		// 设置服务实现类
		factoryBean.setServiceBean(new StudentInterfaceImpl());
		// 设置资源类,如果有多个资源类,可以以“,”隔开。
		factoryBean.setResourceClasses(StudentInterfaceImpl.class);
		// 设置服务地址
		factoryBean.setAddress("http://localhost:9999/hjh");
		// 发布服务
		factoryBean.create();
	}
}

7. 通过CXF+Spring整合发布RESTful服务
   客户端: client7_cxf_spring_RESTful_test.jsp
   服务端: server7_cxf_spring_RESTful
   测试服务: http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/hjh?_wadl 注:_wadl是RESTful的说明
   查询单个学生: http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/hjh/student/query/1
   查询多个学生: http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/hjh/student/queryList/9527?_type=json
   
    客户端页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	window.onload = function() {
		document.getElementsByTagName("input")[0].onclick = function() {
			var xhr;
			if (window.XMLHttpRequest) {
				xhr = new XMLHttpRequest();
			} else {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xhr.open(
					"GET",
					"http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/hjh/student/queryList/9527?_type=json");
			xhr.send();
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					if (xhr.status == 200) {
						var result = xhr.responseText;
						alert(result);
					}
				}
			}
		};
	}
</script>
</head>
<body>
	<input type="button" value="点击查询" />
</body>
</html>

服务端代码:
     StudentInterface.java
package server7_cxf_spring_RESTful;

import java.util.List;
import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import model.Student;

@WebService
@Path("/student") // @Path("/student")就是将请求路径中的“/student”映射到接口上
public interface StudentInterface {
	
	@GET // 指定请求方式, 如果服务端发布的时候指定的是GET(POST), 那么客户端访问时必须使用GET(POST)
	@Produces(MediaType.APPLICATION_XML) // 指定服务数据类型为xml格式, 此时服务地址后不可加?_type=json
	@Path("/query/{id}") // @Path("/query/{id}")就是将"/query"映射到方法上, "{id}"映射到参数上, 多个参数, 以“/”隔开, 放到“{}”中
	// 根据id查询单个学生
	public Student queryStuById(@PathParam("id") Integer id);

	@GET
	@Produces({ MediaType.APPLICATION_XML, "application/json;charset=utf-8" }) // 可以是xml或json格式, 默认是xml
	@Path("/queryList/{classroom}")
	// 查询多个学生
	public List<Student> queryStudentList(@PathParam("classroom") String classroom);
}
    StudentInterfaceImpl.java

package server7_cxf_spring_RESTful;

import java.util.ArrayList;
import java.util.List;
import model.Student;

public class StudentInterfaceImpl implements StudentInterface {

	@Override
	public Student queryStuById(Integer id) {
		Student student = new Student();
		student.setId(id);
		student.setName("张三");
		student.setAge(20);
		return student;
	}

	@Override
	public List<Student> queryStudentList(String classroom) {
		Student student1 = new Student();
		student1.setId(110);
		student1.setName("张三");
		student1.setAge(19);
		student1.setClassroom(classroom);
		
		Student student2 = new Student();
		student2.setId(120);
		student2.setName("李四");
		student2.setAge(23);
		student2.setClassroom(classroom);
		
		List<Student> list = new ArrayList<Student>();
		list.add(student1);
		list.add(student2);
		return list;
	}

}

最后是第5种和第7种方式的配置文件:

    客户端    

    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"
	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>webservice_cxf_spring_client</display-name>
	<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>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>CXF</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>CXF</servlet-name>
		<url-pattern>/ws/*</url-pattern>
	</servlet-mapping>

</web-app>
    applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/cxf"
	xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 								                
	http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 						  
	http://cxf.apache.org/cxf 
   	http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxrs         					   
    http://cxf.apache.org/schemas/jaxrs.xsd 
   	http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
   	
	<!-- 5. client5_cxf_spring_soap, 设置客户端信息, address为发布的服务地址 -->
	<jaxws:client id="client5_cxf_spring_soap" address="http://localhost:8090/day20_webService_cxf_spring_server_practice/ws/weather" serviceClass="client5_cxf_spring_soap.WeatherInterface"></jaxws:client>
	
</beans>
服务端

    web.xml 同客户端
applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/cxf"
	xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 								                
	http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 						  
	http://cxf.apache.org/cxf 
   	http://cxf.apache.org/schemas/core.xsd 
   	http://cxf.apache.org/jaxrs         					   
    http://cxf.apache.org/schemas/jaxrs.xsd 
   	http://cxf.apache.org/jaxws 
   	http://cxf.apache.org/schemas/jaxws.xsd ">
   	
	<!-- 5. server5_cxf_spring_soap, 通过CXF+Spring整合发布SOAP的服务 -->
	<!-- <jaxws:server serviceClass="server5_cxf_spring_soap.WeatherInterface" address="/weather">
		<jaxws:serviceBean>
			<ref bean="weatherInterface" />
		</jaxws:serviceBean>
	</jaxws:server> -->
	<!-- 配置服务实现类 -->
	<!-- <bean name="weatherInterface" class="server5_cxf_spring_soap.WeatherInterfaceImpl"></bean> -->
	
	<!-- 7. server7_cxf_RESTful, 通过CXF+Spring整合发布RESTful服务 -->
	<jaxrs:server address="/hjh">
		<jaxrs:serviceBeans>
			<ref bean="studentInterfaceImpl"/>
		</jaxrs:serviceBeans>
	</jaxrs:server>
	<!-- 配置服务实现类 -->
	<bean name="studentInterfaceImpl" class="server7_cxf_spring_RESTful.StudentInterfaceImpl"></bean>
	
</beans> 

本文Demo地址:点击打开链接
本工程环境: MacOS 10.13.2 eclipse 4.7.2 CXF 3.2.1 JDK 1.8
 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值