CXF集成spring做webservice接口

  一 . cxf 的jar包

  1.cxf-2.3.3.jar

  2.wsdl4j-1.6.2.jar

  3.wss4j-1.5.11.jar

  4.wstx-asl-3.2.0.jar

  5.XmlSchema-1.4.7.jar

  以上没有spring和cxf的依赖包后续更新

 

二. web.xml

<!-- cxf servlet -->
    <servlet>
        <servlet-name>CXFservlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFservlet</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>

三.applicationContext.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:http-conf="http://cxf.apache.org/transports/http/configuration"
    xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd
             http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
             http://cxf.apache.org/transports/http/configuration
             http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/core 
             http://cxf.apache.org/schemas/core.xsd">
             
     <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="synchronousUserImpl" class="cn.chinaunicom.pmis.interfaces.sso.server.impl.SynchronousUserImpl"></bean>
    <jaxws:endpoint id="synchronousUser" implementor="#synchronousUserImpl" address="/synchronousUser"/>
</beans>

四.接口

import javax.jws.WebService;

/**
 * 同步用户webService
 * @author duwenlei
 *
 */
@WebService
public interface SynchronousUser {
    /**
     * 同步用户
     * @param json
     * @return
     */
    boolean syncUser(String json);
}

五.接口实现

import javax.jws.WebService;

import cn.chinaunicom.pmis.interfaces.sso.server.SynchronousUser;

@WebService(endpointInterface="cn.chinaunicom.pmis.interfaces.sso.server.SynchronousUser")
public class SynchronousUserImpl implements SynchronousUser {

    @Override
    public boolean syncUser(String json) {
        System.err.println("success");
        return false;
    }

}

六 . 运行tomcat

访问 http://localhost:8080/pmisx/webservice/synchronousUser?wsdl 成功则cxf部署成功

未完待续

posted @ 2015-11-10 16:19  哎呦喂,我的小祖宗╰つ  阅读(293)  评论(0编辑  收藏  举报