通过CXF,开发soap协议接口(简单明了)

1. 引入cxf的jar包
  pom文件里面直接增加依赖
      < dependency>
          junit
          junit
          4.11
          test
     
     
          org.springframework
          spring- webmvc
          4.0.0.RELEASE 
     
     
           org.apache.cxf
            apache-cxf
           2.4.3
            pom
     

2. 配置web.xml文件
   
   < web-app xmlns= "http://xmlns.jcp.org/xml/ns/javaee"

    xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version= "3.1" >

  < display-name >Archetype Created Web Application
  < context-param >
            contextConfigLocation
           classpath:config/spring/metadataWebService-spring.xml
     
     
           org.springframework.web.context.ContextLoaderListener
     
     
            CXFServlet
           org.apache.cxf.transport.servlet.CXFServlet
     
     
            CXFServlet
            /services/*
     
     
        encodingFilter
        < filter-class> org.springframework.web.filter.CharacterEncodingFilter
       
            encoding
            UTF-8
       
       
            forceEncoding
            true
       
   
   
        encodingFilter
        /*
   

3. 配置cxf.xml文件
    
    < 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:context= "http://www.springframework.org/schema/context"
      xmlns:jaxrs= "http://cxf.apache.org/jaxrs"
      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://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://cxf.apache.org/jaxrs
        http://cxf.apache.org/schemas/jaxrs.xsd" >
     
     
     
     
     
     
     
           
                 
           
     
     
            scope= "prototype" >
           
                
                     
                
           
     
     
           class= "org.apache.cxf.jaxws.spring.JaxWsWebServicePublisherBeanPostProcessor" >
           
           
     
     
     
     < jaxws:server id= "ResumeUpload" serviceClass= "com.sigmatrix.soap.webService.DemoService"
            address= "/ResumeUpload" >
           
           
                
           
           
           
                
           
     

4. 要开放的接口加上cxf服务的注解
   接口类:
   @WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )
   @javax.xml.ws.soap. MTOM
   public interface DemoService {
      @WebMethod
      public String demo( @WebParam(name = "demo") Demo demo);
   }
   接口实现类:
   @Component
   @WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )
   @BindingType (value = "http://www.w3.org/2003/05/soap/bindings/HTTP/" )
   public class DemoServiceImpl implements DemoService {
   public String Demo(Demo demo) {
        String userName = demo.getUserName();
        String password= demo.getPassword();
        return "success";
   }
   Demo实体类:
   public Class Demo() {
        public String userName;
        public String password;

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password= password;
        }
   }
5. 部署到tomcat启动即可,测试访问   ip:端口号//项目名称/services/

你可能感兴趣的:(Java)