CXF的简单配置应用

Server:

     //1.创建发布服务的工厂
        JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();

        //2.设置服务地址
        factoryBean.setAddress("http://localhost:8888/book");

        //3.设置服务接口,发布的服务
        factoryBean.setServiceClass(BookService.class);

        //4。设置服务实现
        factoryBean.setServiceBean(new BookServiceImpl());
        //5.创建服务并启动

        Server server=factoryBean.create();
        server.start();

Client:

    //1.代理服务工厂
        JaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean();
        //2.设置port
         factoryBean.setAddress("http://localhost:8888/book?wsdl");
        //3.服务实现
       factoryBean.setServiceClass(BookService.class);
        //4.创建客户端
        BookService service=(BookService)factoryBean.create();

Cxf和SpringMVC整合

server端:

web.xml的配置:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <!--编码过滤器-->
     <filter>
       <filter-name>encodingFilter</filter-name>
       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
       <init-param>
         <param-name>encoding</param-name>
         <param-value>UTF-8</param-value>
       </init-param>
       <init-param>
         <param-name>forceEncoding</param-name>
         <param-value>true</param-value>
       </init-param>
     </filter>
     <filter-mapping>
       <filter-name>encodingFilter</filter-name>
       <url-pattern>/*</url-pattern>
     </filter-mapping>
  <!--CXFServlet-->
  <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:spring-cxf.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <!---->
    <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>

</web-app>

Server端的springmvc配置:

<?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:cxf="http://cxf.apache.org/jaxws"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.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">

     <context:component-scan base-package="com.etoak"></context:component-scan>

    <!--发布服务
       address:服务地址
       serviceClass:
       serviceBean:
    -->
    <cxf:server address="/book" serviceClass="com.etoak.service.BookService">
       <cxf:serviceBean>
            <ref bean="impl"></ref>
        </cxf:serviceBean>
    </cxf:server>

</beans>

Client端的配置:

<?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:cxf="http://cxf.apache.org/jaxws"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.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">
	
	   <cxf:client address="http://localhost:8080/ws/book"
	   serviceClass="com.etoak.service.BookService"
	   id="clientbookService"
	   >


	   </cxf:client>
</beans>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值