spring boot集成webservice接口
生活随笔
收集整理的這篇文章主要介紹了
spring boot集成webservice接口
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
依賴集成
當(dāng)前spring boot 版本是 2.0.1.RELEASE, 其對應(yīng)的cxf依賴版本為:3.2.4, 詳情如下:
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxws</artifactId><version>3.2.4</version> </dependency>代碼實現(xiàn)
接口實現(xiàn)
package com.spring.login.api; import javax.jws.WebService; /*** 天氣查詢*/@WebServicepublic interface WeatherService {/*** 查詢溫度* @param city* @return*/String queryTemperature(String city);/*** 查詢降雨量* @param city* @return*/String queryRainfall(String city);/*** 查詢風(fēng)力* @param city* @return*/String queryWindLevel(String city);}接口實現(xiàn)類:
package com.spring.login.api.impl;import com.spring.login.api.WeatherService;import org.springframework.stereotype.Component;import javax.jws.WebService; /*** 天氣管理*/ @Component @WebService public class WeatherServiceImpl implements WeatherService {@Overridepublic String queryTemperature(String city) {return city + ": 30攝氏度";}@Overridepublic String queryRainfall(String city) {return city + ": 3500毫米";}@Overridepublic String queryWindLevel(String city) {return city + ": 5-7級別";}}實例化配置
package com.spring.login.config;import com.spring.login.api.WeatherService; import org.apache.cxf.Bus; 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.annotation.Resource; import javax.xml.ws.Endpoint;@Configuration public class WebServiceConfg {@Resourceprivate Bus bus;@Resourceprivate WeatherService weatherService;@Beanpublic ServletRegistrationBean servletRegistrationBean(){return new ServletRegistrationBean(new CXFServlet(),"/services/*");}@Beanpublic Endpoint endpoint(){EndpointImpl endpoint = new EndpointImpl(bus,weatherService);endpoint.publish("/weatherService");return endpoint;}}訪問地址: http://localhost:9090/services/weatherService?wsdl
客戶端接收
方式一:
該方式要求接口的命名空間和接口的目錄一致,代碼如下:
總結(jié)
以上是生活随笔為你收集整理的spring boot集成webservice接口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MultipartFile 文件上传
- 下一篇: EasyExcel 2 上传 下载