cxf-spring-pratice-client

来源:互联网 发布:培训机构程序员 编辑:程序博客网 时间:2024/06/08 11:03

与spring集成时,客户端的相关配置.

2017/11/15 时隔六个月, 重新下组织格式和内容.

1. 引入cxf相关的依赖

1.1 使用maven

<dependency>    <groupId>org.apache.cxf</groupId>    <artifactId>cxf-rt-frontend-jaxws</artifactId>    <version>3.1.1</version></dependency><dependency>    <groupId>org.apache.cxf</groupId>    <artifactId>cxf-rt-transports-http</artifactId>    <version>3.1.1</version></dependency>

1.2 直接引入相关jar

真心不建议采用这种方式!

asm-5.0.4.jarcxf-core-3.1.1.jarcxf-rt-bindings-soap-3.1.1.jarcxf-rt-bindings-xml-3.1.1.jarcxf-rt-databinding-jaxb-3.1.1.jarcxf-rt-frontend-jaxws-3.1.1.jarcxf-rt-frontend-simple-3.1.1.jarcxf-rt-transports-http-3.1.1.jarcxf-rt-ws-addr-3.1.1.jarcxf-rt-ws-policy-3.1.1.jarcxf-rt-wsdl-3.1.1.jarjaxb-core-2.2.11.jarjaxb-impl-2.2.11.jarneethi-3.0.3.jarstax2-api-3.1.4.jarwoodstox-core-asl-4.4.1.jarwsdl4j-1.6.3.jarxml-resolver-1.2.jarxmlschema-core-2.2.1.jar

2. 创建相关类

2.1 IHelloWorld接口

与服务端完全一致的接口,建议将接口单独为一个jar.

@WebServiceinterface IHelloWorld {    String sayHello(@WebParam(name = "username") String username);    Map<String, Object> getObj(@WebParam(name = "username")String username, @WebParam(name = "sexy")String sexy);}

3. Spring配置

3.1 spring-cxf-client.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: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-4.0.xsd    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-4.0.xsd      http://cxf.apache.org/jaxws       http://cxf.apache.org/schemas/jaxws.xsd  "><!--     官方文档:     http://cxf.apache.org/docs/writing-a-service-with-spring.html              *** Create a Client (More Manual Way) ***    <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">        <property name="serviceClass" value="com.kq.webservice.xmlpservice"/>        <property name="address" value="${webservice.service.address}/xmlpservice"/>    </bean>    <bean id="xmlpServiceClient" class="com.kq.webservice.xmlpservice" factory-bean="clientFactory" factory-method="create"/>          -->    <jaxws:client id="xmlpServiceClient"              serviceClass="com.kq.webservice.xmlpservice"              address="${webservice.service.address}/xmlpservice" /></beans>

3.2 spring.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:context="http://www.springframework.org/schema/context"  xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-4.0.xsd  "><!--导入上面创建的文件--><import resource="spring-cxf-client.xml"/><!--导入配置信息--><context:property-placeholder location="classpath:config/db.properties" /></beans>

4. 参考链接

  1. http://cxf.apache.org/docs/writing-a-service-with-spring.html - 官方文档
0 0
原创粉丝点击