Springboot项目实现webservice接口(支持soap1.1协议和soap1.2协议)

Springboot项目实现webservice接口

  • 新建项目
    • pom
      • 配置
        • 启动类
        • 配置类
        • WSDL接口
        • soap1.1协议实现类
        • soap1.2协议实现类

新建项目

  1. 打开idea,新建Springboot项目 File->New->Project->选择Spring Initializr->next
    Springboot项目实现webservice接口(支持soap1.1协议和soap1.2协议)_第1张图片
    Springboot项目实现webservice接口(支持soap1.1协议和soap1.2协议)_第2张图片

pom


        org.springframework.boot
        spring-boot-starter-parent
        2.2.1.RELEASE
    

    com.demo
    demo
    0.0.1-SNAPSHOT
    jar

    
        1.8
        3.2.4
        1.4.8
    
    
    
        
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-logging
        
        
        
            org.apache.cxf
            cxf-rt-frontend-jaxws
            ${cxf.version}
        
        
            org.apache.cxf
            cxf-rt-transports-http
            ${cxf.version}
        

        
            com.thoughtworks.xstream
            xstream
            ${xstream.version}
        

        
            com.alibaba.nacos
            nacos-client
            1.2.1
        
        
            javax.json
            javax.json-api
            1.1
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
                org.apache.maven.plugins
                maven-jar-plugin
                3.1.2
                
                    
                        application.properties
                        default.properties
                    
                
            
        
        demo
    

配置

server.port=8058
spring.application.name=demo
server.tomcat.uri-encoding=UTF-8

启动类
package com.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication{

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
配置类
package com.demo.ws.wsInterface;

import com.demo.ws.wsInterface.impl.WebServicesImpl1_1;
import com.demo.ws.wsInterface.impl.WebServicesImpl1_2;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class WebServicesConfiguration {
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

   @Bean(name = "wbsBean")
    public ServletRegistrationBean dispatcherServlet() {
        ServletRegistrationBean wbsServlet = new ServletRegistrationBean(new CXFServlet(), "/demo/*");
        return wbsServlet;
    }

    /**
     * SOAP协议 1.1
     */
    @Bean
    public Endpoint endpointPurchase1_1(SpringBus springBus, WebServicesImpl1_1 service) {
        EndpointImpl endpoint = new EndpointImpl(springBus, service);
        endpoint.publish("/services");
        System.out.println("soap1.1服务发布成功!地址为:http://127.0.0.1:8058/demo/services");
        return endpoint;
    }

    /**
     * SOAP协议 1.2
     */
    @Bean
    public Endpoint endpointPurchase1_2(SpringBus springBus, WebServicesImpl1_2 service) {
        EndpointImpl endpoint = new EndpointImpl(springBus, service);
        endpoint.publish("/services");
        System.out.println("soap1.2服务发布成功!地址为:http://127.0.0.1:8058/demo/services");
        return endpoint;
    }
}

WSDL接口
package com.demo.ws.wsInterface;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface IWebServices {

    @WebMethod(action = "http://wsInterface.ws.demo.com/MethodName")
    String MethodName(@WebParam(targetNamespace = "http://wsInterface.ws.demo.com/") String inParamXml);

}
soap1.1协议实现类
package com.demo.ws.wsInterface.impl;

import com.demo.ws.wsInterface.IWebServices;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;


/* SOAP协议 1.1 */
@BindingType(value = SOAPBinding.SOAP11HTTP_BINDING)
@WebService
@Service
public class WebServicesImpl1_1 implements IWebServices{

    @Override
    public String WebMethod(String inParamXml) {
        return "";
    }
}
soap1.2协议实现类
package com.demo.ws.wsInterface.impl;

import com.demo.ws.wsInterface.IWebServices;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;


/* SOAP协议 1.2 */
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@WebService
@Service
public class WebServicesImpl1_2 implements IWebServices{

    @Override
    public String WebMethod(String inParamXml) {
        return "";
    }
}

你可能感兴趣的:(spring,boot,java,intellij-idea)