栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

Springboot项目实现webservice接口

新建项目

pom

配置类

启动类配置类WSDL接口soap1.1协议实现类soap1.2协议实现类

新建项目

    打开idea,新建Springboot项目 File->New->Project->选择Spring Initializr->next

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
    @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;
    }

    
    @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;



@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;



@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@WebService
@Service
public class WebServicesImpl1_2 implements IWebServices{

    @Override
    public String WebMethod(String inParamXml) {
        return "";
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/759371.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号