日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring boot集成webservice接口

發(fā)布時間:2025/3/19 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

客戶端接收

方式一:
該方式要求接口的命名空間和接口的目錄一致,代碼如下:

public String queryService(){JaxWsProxyFactoryBean jaxWsProxyFactoryBeanx = new JaxWsProxyFactoryBean();jaxWsProxyFactoryBeanx.setAddress(http://127.0.0.1:9090/services/weatherService?wsdl);jaxWsProxyFactoryBeanx.setServiceClass(WeatherService.class);WeatherService weatherService = (WeatherService) jaxWsProxyFactoryBeanx.create();return weatherService .queryTemperature("南京"); } 與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的spring boot集成webservice接口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。