CXF使用
一.服务端:
1.web.xml配置
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>config-location</param-name>
<param-value>classpath:cxf.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
2.cxf.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:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />
<!-- 第一种发布服务方式 -->
<!-- <bean id="helloService" class="com.zhou.service.impl.HelloServiceImpl"></bean>
<jaxws:server id="myService" address="/cxfService">
<jaxws:serviceBean>
<ref bean="helloService"/>
</jaxws:serviceBean>
</jaxws:server> -->
<!-- 第二种服务发布方式 -->
<jaxws:endpoint address="/cxfService" implementor="com.zhou.service.impl.HelloServiceImpl">
</jaxws:endpoint>
</beans>
3.创建接口service和接口实现类serviceImpl,接口上加@WebService,访问地址:http://127.0.0.1:8080/CXF-server/service/cxfService?wsdl
import javax.jws.WebService; @WebService
public interface HelloService {
public String sayHello(String name);
} import com.zhou.service.HelloService; public class HelloServiceImpl implements HelloService{ @Override
public String sayHello(String name) {
System.out.println("CXF服务端被调用...");
return "hello"+name;
}
}
4.加入相应jia包
二.客户端
1.cxf.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:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<!-- <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" /> --> <!-- 注册CXF客户端代理对象,通过spring框架创建这个代理对象,使用代理对象实现远程调用 -->
<jaxws:client id="myClient"
address="http://192.168.0.158:8080/CXF-server/service/cxfService"
serviceClass="com.zhou.service.HelloService">
</jaxws:client>
</beans>
2.客户端代码
import javax.jws.WebService; /**
* targetNamespace对应http://+服务端包名
* name对应类名
* @author Administrator
* @date{date}
*/
@WebService(targetNamespace = "http://service.zhou.com/", name = "HelloService")
// 接口名称可以不一样
public interface HelloService {
// 方法名称、参数格式必须保持一致,否则无法找到服务的实现的方法
public String sayHello(String name);
}
注:服务开就启动CXF服务需修改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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>crm_heima32</display-name> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cxf.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 配置CXF框架提供的Servlet -->
<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>/service/*</url-pattern>
</servlet-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>
CXF使用的更多相关文章
- java调用CXF WebService接口的两种方式
通过http://localhost:7002/card/services/HelloWorld?wsdl访问到xml如下,说明接口写对了. 2.静态调用 // 创建WebService客户端代理工厂 ...
- webService学习之路(三):springMVC集成CXF后调用已知的wsdl接口
webService学习之路一:讲解了通过传统方式怎么发布及调用webservice webService学习之路二:讲解了SpringMVC和CXF的集成及快速发布webservice 本篇文章将讲 ...
- webService学习之路(二):springMVC集成CXF快速发布webService
继上一篇webService入门之后,http://www.cnblogs.com/xiaochangwei/p/4969448.html ,现在我将我周六在家研究的结果公布出来 本次集成是基于之前已 ...
- CXF:根据werservice代码生成WSDL(转)
原文:http://hongyegu.iteye.com/blog/619147,谢谢! import org.apache.cxf.tools.java2ws.JavaToWS; import ne ...
- webservice入门实例,CXF方式
1.下载CXF,及先关jar包. CXF 下载地址:http://cxf.apache.org/download.html,选择"File"列中的zip格式下载.解压后可以看到一些 ...
- 脱离spring集成cxf(基于nutz框架)
什么是webService WebService是一种跨编程语言和跨操作系统平台的远程调用技术. 理论资料: http://blog.csdn.net/wooshn/article/details/8 ...
- WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)
最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...
- WebService -- Java 实现之 CXF ( 使用:Spring+CXF+Tomcat发布webService)
1. 新建一个Maven项目,选择webapp模板,命名为WS_Spring_CXF_Tomcat 2. 在POM.xml中添加Spring和CXF的依赖 <!-- 添加 Spring depe ...
- WebService -- Java 实现之 CXF ( 添加系统预定义的拦截器)
1. 概述 CXF允许我们在webservice的in/out位置添加拦截器.拦截器有两大分类,一类是系统预定义的:另一类是自定义拦截器. 2. 在server端添加拦截器. JaxWsServerF ...
- cxf webservice 生成wsdl方法参数名称为arg0问题
在通过cxf生成webservice服务时,如果你是用ServerFactoryBean,那么在生成wsdl时,方法的参数名称会被自动命名为arg0,arg1...,如: <xsd:comple ...
随机推荐
- JS 数组中对象去重 reduce 用法
对于数组对象,传统的去重方法无能为力,至于forEach().filter()等迭代方法也不好使:真正能做到优雅去重的,是ES5新增加的一个方法——reduce() 高手给的,完美方法 let log ...
- Spring AutoWire
AutoWire 有 ByType ,ByName两种主要使用方式 public class Boss { @Autowired private Car car; public Car getCar( ...
- JDK8新特性04 方法引用与构造器引用
import java.io.PrintStream; import java.util.Comparator; import java.util.function.*; /** * 一.方法引用 * ...
- 【bzoj 3110】[Zjoi2013]K大数查询
Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c.如果是2 a b c形式,表示询问从第a个位置到第b个位 ...
- excel数据处理,公式
1. 替换 SUBSTITUTE(字符串, 原字符串, 新字符串) =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(L2,"镇",""),& ...
- easyui 进阶之tree的常见操作
前言 easyui是一种基于jQuery的用户界面插件集合,它为创建现代化,互动,JavaScript应用程序,提供必要的功能,完美支持HTML5网页的完整框架,节省网页开发的时间和规模.非常的简单易 ...
- windows Apache 环境下配置支持HTTPS的SSL证书
windows Apache 环境下配置支持HTTPS的SSL证书 1.准备工作 1)在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有SSL版本的A ...
- shell实现带颜色输出的进度条
1.基础版 #!/bin/bash b='' ;$i<=;i+=)) do printf "执行进度 :[%-50s]%d%%\r" $b $i sleep 0.001 b= ...
- 如何设置vmware 让别人连接你的虚拟机
参考链接: http://blog.csdn.net/yuan1590/article/details/53504042 http://blog.csdn.net/u012110719/article ...
- java.lang.RuntimeException: Cannot create a secure XMLInputFactory 异常处理
背景:本人在近日的webservice CXF接口的编写调试过程中,发现一个很奇怪的现象--我在本地对接口进行往返请求时完全没有问题,不管是main方法直接调用还是业务场景里调用都无问题,在其他同 ...