SpringBoot整合WebService服务端

3 篇文章 0 订阅
1 篇文章 0 订阅

SpringBoot整合WebService服务端

1. 1. 定义一个接口WebService的接口

package com.cc.service;

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

/**
 * 程序入口: http://127.0.0.1:8080/deliveryOrder/webservice---config配置文件中配置
 * targetNamespace :实现类包名的反写,加前缀http: 和后缀com
 * 直接访问接口地址:http://127.0.0.1:8080/deliveryOrder/webservice/analysiSAPOrderXML?wsdl
 */
@WebService(targetNamespace = "http://impl.service.cc.com/")
public interface WebSapToQLAHPWebService {

	@WebMethod
	String analysiSAPOrderXML(@WebParam(name = "orders") String orders);
}


- 2. 实现WebService接口

package com.cc.service.impl;

import com.cc.service.WebSapToQLAHPWebService;
import org.springframework.stereotype.Service;

import javax.jws.WebService;

/**
 * @Author: 01375318
 * @Date: 2019/10/22 14:53
 * endpointInterface :接口的包名称全路径
 * targetNamespace:实现类包名的反写,加前缀http: 和后缀com
 * analysiSAPOrderXML :CxfConfig配置文件暴露的方法名称
 */
@Service
@WebService(serviceName = "analysiSAPOrderXML", targetNamespace = "http://impl.service.cc.com", endpointInterface = "com.cc.service.WebSapToQLAHPWebService")
public class WebSapToQLAHPWebServiceImpl implements WebSapToQLAHPWebService {


	@Override
	public String analysiSAPOrderXML(String orders) {
		return "执行成功了!" + orders;
	}
}


- 3. 编写WebService接口配置文件

package com.cc.config;


import com.cc.service.WebSapToQLAHPWebService;
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.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import javax.xml.ws.Endpoint;


@SpringBootConfiguration
public class CxfConfig {

	@Autowired
	private WebSapToQLAHPWebService webServiceDemoService;

	/**
	 * 注入servlet  bean name不能dispatcherServlet 否则会覆盖dispatcherServlet
	 *
	 *   deliveryOrder/webservice : 配置程序的入口,可随便定义
	 *
	 * @return
	 */
	@Bean(name = "cxfServlet")
	public ServletRegistrationBean cxfServlet() {
		return new ServletRegistrationBean(new CXFServlet(), "/deliveryOrder/webservice/*");
	}


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


	/**
	 * 注册WebServiceDemoService接口到webservice服务
	 * analysiSAPOrderXML:对应webService接口的f方法名称
	 *
	 * @return
	 */
	@Bean(name = "WebServiceDemoEndpoint")
	public Endpoint webserviceEndpoint() {
		EndpointImpl endpoint = new EndpointImpl(springBus(), webServiceDemoService);
		endpoint.publish("/analysiSAPOrderXML");
		return endpoint;
	}
}

- 4. WebService服务所需要的依赖

      <!-- webservice cxf 整合WebService所依赖的jar包start -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>3.2.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <!-- webservice cxf 整合WebService所依赖的jar包end -->

- 5. 暴露对外测试地址

程序入口: http://127.0.0.1:8080/deliveryOrder/webservice-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值