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 ...
随机推荐
- 使用JAVA数组实现顺序栈
1,首先总结一下线性表(分为顺序表和链接表,[即顺序存储结构和链式存储结构的区别])和栈(顺序栈和链接栈)还有队列(顺序队列和链接队列)的JAVA类库中的实现: java.util.ArrayList ...
- [C++]基于Curses库的实时系统监测可视化系统-2017-12-09 15-07-42
Congratulations 0.0 技术记录 [1] [C++]Linux之Ubuntu下编译C程序出现错误:“ stray ‘\302'或者'\240' in program”的解决方案 [2 ...
- windows平台下利用Nginx做负载均衡
1.下载nginx(http://nginx.org/en/download.html)安装包,解压,并使用cmd命令转到nginx.exe所在的目录 2.执行cmd命令start nginx启动ng ...
- app-web 开发 追溯debug
1.iphone5 运行vue项目时,方法格式:fun(){}这种格式容易不显示页面 2.vue未绑定上数据有可能是js文本过大,手机内存不足引起的 3.根据方法走向追溯debug 4.一定要用try ...
- 网址,域名,IP,主机名的区别
域名 通常 Internet 主机域名的一般结构为:主机名.三级域名.二级域名.顶级域名(又称为一级域名). 二级域名及其以上级别的域名,统称为子域名,有多少个点就是几级域名 顶级域名分为两类 ...
- axios 在Vue全局引入的方法
在main.js中: import axios form axios Vue.prototype.$axios = axios 组件中使用: submitFrom () { this.$axios.g ...
- H - Rescue the Princess ZOJ - 4097 (tarjan缩点+倍增lca)
题目链接: H - Rescue the Princess ZOJ - 4097 学习链接: zoj4097 Rescue the Princess无向图缩点有重边+lca - lhc..._博客园 ...
- CNN学习入门
https://blog.csdn.net/ice_actor/article/details/78648780
- 微信小程序入门八头像上传
1. action-sheet 底部弹出可选菜单组件 2. wx.uploadFile 将本地资源上传到服务器 3. wx.chooseImage 从本地相册选择图片或使用相机拍照. 4. wx.pr ...
- log4j中Logger.getLogger()加载一个类提示错误
转载自:https://blog.csdn.net/q3229270/article/details/77986687 ----------------------------- 错误提示如下:The ...