1.Create project with maven
2.add in pom.xml
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.4</version>
</dependency>
and it in build section
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
3.Copy the wsdl to src/main/resources/wsdl/;
4.add code generator plugin for generating java code.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/cxf-codegen</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/authService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
5.compile the project
6.test it
public class App
{
public static void main( String[] args )
{
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(AuthService.class);
factory.setAddress("http://localhost:8080/cxf/service/cxfAuth");
AuthService client = (AuthService)factory.create();
Employee employee = client.getEmployee("2323");
System.out.println("Name: " + employee.getFirstName() + " " + employee.getLastName());
System.exit(0);
}
}
7.done.
8.using spring, create a config
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="cxfClient" serviceClass="org.yy.cxf.service.AuthService"
address="http://localhost:8080/cxf/service/cxfAuth" />
</beans>
9. Test code
public class App {
public static void main(String[] args) {
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:appctx.xml");
ctx.registerShutdownHook();
AuthService client = (AuthService) ctx.getBean("cxfClient");
Employee employee = client.getEmployee("2323");
System.out.println("Name: " + employee.getFirstName() + " " + employee.getLastName());
System.exit(0);
}
}
10.ok
分享到:
相关推荐
cxf+spring+client+springmvc
本实例是基于CXF的一个客户端的实现,使用maven生成客户端代码,集成spring配置客户端实现类,访问外部接口。“CXF契约优先开发方式”中的实例为服务器端代码。
springboot整合CXF发布webservice和客户端调用 项目中每个类都有详细的注释,保证都能看懂,不失为一个学习springboot整合cxf来学习webservice发布调用的好例子
cxf client
NULL 博文链接:https://openstudy.iteye.com/blog/1114916
NULL 博文链接:https://flame-zhou.iteye.com/blog/2206232
CXF实例源代码 客户端调用 web service 入门教程
CXF动态调用webservice.demo测试用例,亲测通过,拿走不谢
wsdl2java源码springboot-apachecxf-client 本项目演示了如何在Springboot中实现apachecxf客户端,以及如何为客户端调用生成wsdltojava。 Springboot-apachecxf-jaxws 示例 此应用程序展示了如何使用 apachecxf ...
CXF 一个完整的webService(整合客户端和服务端),自己开发,自己测试,完全有效,整合集成了客户端和服务端双向的工能。
JAVA 用 Apache CXF 调用 .NET 服务端 WebService 代码 整个JAVA工程的压缩,导入到myeclipse可直接运行,如果只想浏览下,请访问:http://blog.csdn.net/wqmain/article/details/8216331
NULL 博文链接:https://abingpow.iteye.com/blog/2002196
赠送jar包:cxf-rt-rs-client-3.0.1.jar; 赠送原API文档:cxf-rt-rs-client-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-client-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-rs-client-3.0.1.pom; 包含...
使用CXF开发Web Service,包含服务器端和客户端
懒惰的CXF关于更快地部署 CXF 客户端(开发中)。 该库为 CXF 的 JAXRSClientFactoryBean 和 JaxWsProxyFactoryBean 提供了替代品。 两者都有一个额外的惰性参数,用于控制工厂是否创建代理的、未初始化的(惰性)...
xfire server 支持对象的传递和对象的返回,对应的cxf client cxf 1.2.6 client
cxf spring server client demo.rar soap webservice
apache-cxf-2.7.7以及cxf客户端所需要的jar包,命令生成webservice客户端
#Cxf客户端记录器 概述 记录Web服务是开发世界的一个普遍问题。 该项目旨在以不同的方式解决此问题。 许多人编写了自己的日志记录机制以通过拦截器记录Web服务。 该项目代替您完成了整个肮脏的工作。 我们的拦截器将...
测试 cxf 2.1.3客服端 调用 xfire 1.2.6 的服务端 的对象传递,与对象返回,服务端见xfire 1.2.6 server