cxf version:2.7
jre:1.7
建立web工程cxfweb,将cxf的lib目录下面的所有jar包进入到web工程
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- cxf的配置文件位置 -->
<param-value>classpath:cxf-servlet.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>/cxf/*</url-pattern>
</servlet-mapping>
cxf-servlet.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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.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
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- 引入以下文件,以保证不会出错,文件在jar包里-->
<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" />
<!-- id:唯一标示 serviceClass:接口类型 address:服务的请求url-->
<jaxws:server id="helloService" serviceClass="com.wdh.ws.cxf.IHelloService" address="/hello">
<jaxws:serviceBean>
<!-- 服务的实现类 -->
<bean class="com.wdh.ws.cxf.HelloServiceImpl"></bean>
</jaxws:serviceBean>
<!-- 加入请求的消息拦截器,不加也可以 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<!-- 加入响应的消息拦截器,不加也可以 -->
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server>
</beans>
java 代码:
package com.wdh.ws.cxf;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)//sopa 1.2
public interface IHelloService {
String sayHello(String name);
}
package com.wdh.ws.cxf;
public class HelloServiceImpl implements IHelloService {
@Override
public String sayHello(String name) {
return "hello " + name;
}
}
如果我的wen工程路径为:
http://192.168.1.116:9999/cxfweb
那么该webservice的地址为:
http://192.168.1.116:9999/cxfweb/cxf/hello?wsdl
客户端生成代理对象:
启动命令行,切换到cxf的bin目录,运行
D:\apache-cxf-2.7.11\bin>wsdl2java -d e: http://192.168.1.116:9999/cxfweb/cxf/hello?wsdl
客户端测试代码:
package com.wdh.ws.cxf;
public class CxfTest {
public static void main(String[] args) {
IHelloServiceService helloServiceService = new IHelloServiceService();
IHelloService helloService = helloServiceService.getIHelloServicePort();
String str = helloService.sayHello("jack");
System.out.println(str);
}
}
相关推荐
Spring集成Cxf调用WebServices
webService实现 cxf2.7.5 与 spring3.0集成 完整流程,内涵全部jar ,下载集合运行
本示例用cxf2.6.1+spring3.1.0+hibernate3.6 开发web services . 包括客户端是java project, cxf_010 服务器端是个web程序cxf_web_010. 其中客户端的com.dx.client 包下的代码是通过wsdl2java的命令生成,复制到...
Spring集成Cxf暴露WebServices示例
Springboot整合CXF发布Web service和客户端调用(用户和密码验证)打开及用
CXF跟Spring集成的 WebServer实例 由于大小限制 没有上传Jar包,Cxf版本为 apache-cxf-2.3.0 可以官网下载http://cxf.apache.org/
完整的代码详解,让您更快的上手 jar包代码都是测试过的客户端和服务端
使用spring集成cxf,在两个web project里发布及调用webservice server端使用spring+springmvc+mybatis+cxf,client端使用struts2+spring+hibernate+cxf 两个工程均为myeclipse project,包含所有除myeclipse自带以外...
2.web工程的web.xml中配置CXFServlet <!-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org....
源码里面包含了了一个简单的插入功能,主要是为了测试mybatis是否连接上数据库的时候写的测试类,作为一个刚学java,被抓壮丁的写服务器端的妹子,我只想说,画了我3周...如题,基于maven项目的ssm框架和cxf框架的整合。
基于spring和CXF发布webservice,包含java本地发布和调用及web发布和调用。
Java web service 入门示例,使用 JAX_WS API 开发,使用 CXF 发布,集成 Spring ,Spring orm 基于 JPA 开发 DAO, 并使用 Spring data jpa 简化 DAO 实现。
spring-expression-3.0.7.RELEASE.jar,spring-hibernate3.jar,spring-jms-3.0.7.RELEASE.jar,spring-tx-3.0.7.RELEASE.jar,spring-web-3.0.7.RELEASE.jar,sqljdbc4.jar,stax2-api-3.1.1.jar,velocity-1.7.jar,WHICH_...
Web Service是一种构建应用程序的普遍模型,可以在任何支持网络通信的操作系统中实施运行;它是一种新的webs应用程序分支,是自包含、自描述、模块 化的应用,可以发布、定位、通过web调用。
Apache CXF是一个开源的Service框架,它实现了JCP与Web Service中一些重要标准。CXF简化了构造,集成,面向服务架构(SOA)业务组件与技术的灵活复用。在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式...
NULL 博文链接:https://leiwuluan.iteye.com/blog/1171696
WebService入门案例,使用CXF框架,与Spring进行整合,包括客户端工程和服务端工程。
有大量简单的 API 用来快速地构建代码优先的 Services,各种 Maven 的插件也使集成更加容易,支持 JAX-WS API ,支持 Spring 2.0 更加简化的 XML 配置方式,等等。支持二进制和遗留协议:CXF 的设计是一种可插拨的...
apache-cxf-2.7.10,java webservices开发相关jar包,与Spring集成
Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-...Spring 进行无缝集成。