最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot WebService服務(wù)端&客戶端使用案例教程

 更新時(shí)間:2023年10月20日 10:21:28   作者:知識(shí)淺談  
這篇文章主要介紹了SpringBoot WebService服務(wù)端&客戶端使用案例教程,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

服務(wù)端:

依賴

<!--        webservice相關(guān)依賴-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.2.0</version>
        </dependency>

服務(wù)接口

package com.example.demo.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
 * @author: Yinlei
 * Package: com.example.demo.service
 * @date: 2023-10-18 8:40
 * @Description: webservice測(cè)試
 * @version: 1.0
 */
@WebService(name = "HelloWebService",
targetNamespace = "http://helloWebService.service.demo.example.com")
public interface HelloWebService {
    @WebMethod
    @WebResult(name = "resultName")
    String get(@WebParam(name = "name") String name);
}

服務(wù)接口實(shí)現(xiàn)類

package com.example.demo.service.Impl;
import com.example.demo.service.HelloWebService;
import org.springframework.stereotype.Service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
 * @author: Yinlei
 * Package: com.example.demo.service.Impl
 * @date: 2023-10-18 8:46
 * @Description:
 * @version: 1.0
 */
@Service
@WebService(name = "HelloWebService",
        targetNamespace = "http://helloWebService.service.demo.example.com", //命名空間,一般是對(duì)應(yīng)的路徑反過(guò)來(lái)
        endpointInterface = "com.example.demo.service.HelloWebService")  //實(shí)現(xiàn)接口的地址
public class HelloWebServiceImpl implements HelloWebService {
    @Override
    public String get( String name) {
        return name;
    }
}

cxf配置類

package com.example.demo.config;
import com.example.demo.service.HelloWebService;
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.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
/**
 * @author: Yinlei
 * Package: com.example.demo.config
 * @date: 2023-10-18 10:09
 * @Description: Cxf配置類
 * @version: 1.0
 */
@Configuration
public class CxfConfig {
    @Autowired
    private HelloWebService helloWebService;
    @Bean
    public ServletRegistrationBean disServlet(){
        return new ServletRegistrationBean(new CXFServlet(),"/webService/*"); //webservice下的請(qǐng)求將有CXFServlet處理
    }
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return  new SpringBus();
    }
    @Bean
    public Endpoint endpoint(){
        EndpointImpl endpoint = new EndpointImpl(springBus(), helloWebService);
        endpoint.publish("/helloWebservice");
        return endpoint;
    }
}

客戶端

@GetMapping("/get1")
public String get1() throws MalformedURLException {
    //創(chuàng)建WSDL文件的URL,這個(gè)參數(shù)為暴露webervice的網(wǎng)址
    URL wsdlLocation = new URL("http://localhost:9000/webService/helloWebservice?wsdl");
    //創(chuàng)建服務(wù)名稱:第一個(gè)參數(shù)為命名空間地址,第二個(gè)參數(shù) 為本地部分的命名 HelloWebServiceImplService  這個(gè)是對(duì)應(yīng)的實(shí)現(xiàn)類名加上Service
    QName serviceName = new QName("http://helloWebService.service.demo.example.com", "HelloWebServiceImplService");
    Service service = Service.create(wsdlLocation, serviceName);
    //獲取服務(wù)實(shí)現(xiàn)類  參數(shù)為對(duì)應(yīng)的服務(wù)接口.class
    HelloWebService port = service.getPort(HelloWebService.class);
    //調(diào)用方法
    String asd = port.get("asd");
    return asd;
}

到此這篇關(guān)于SpringBoot WebService服務(wù)端&amp;客戶端使用教程的文章就介紹到這了,更多相關(guān)SpringBoot WebService服務(wù)端內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • WebSocket實(shí)現(xiàn)聊天室業(yè)務(wù)

    WebSocket實(shí)現(xiàn)聊天室業(yè)務(wù)

    這篇文章主要為大家詳細(xì)介紹了WebSocket實(shí)現(xiàn)聊天室業(yè)務(wù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Dubbo之降級(jí)Mock源碼分析

    Dubbo之降級(jí)Mock源碼分析

    這篇文章主要為大家介紹了Dubbo降級(jí)Mock源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • SpringBoot整合BCrypt實(shí)現(xiàn)密碼加密

    SpringBoot整合BCrypt實(shí)現(xiàn)密碼加密

    這篇文章主要為大家詳細(xì)介紹了SpringBoot整合BCrypt進(jìn)行密碼加密,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • JeecgBoot代碼生成器自定義請(qǐng)求接口實(shí)例

    JeecgBoot代碼生成器自定義請(qǐng)求接口實(shí)例

    文章介紹了如何在使用代碼生成器生成的頁(yè)面中添加啟用/停用功能,通過(guò)修改List.vue頁(yè)面并添加必要的請(qǐng)求頭token來(lái)解決身份認(rèn)證失敗的問(wèn)題,同時(shí),還講述了如何在菜單管理、角色管理中進(jìn)行權(quán)限配置,以確保按鈕功能生效
    2026-01-01
  • SpringBoot發(fā)送異步郵件流程與實(shí)現(xiàn)詳解

    SpringBoot發(fā)送異步郵件流程與實(shí)現(xiàn)詳解

    這篇文章主要介紹了SpringBoot發(fā)送異步郵件流程與實(shí)現(xiàn)詳解,Servlet階段郵件發(fā)送非常的復(fù)雜,如果現(xiàn)代化的Java開(kāi)發(fā)是那個(gè)樣子該有多糟糕,現(xiàn)在SpringBoot中集成好了郵件發(fā)送的東西,而且操作十分簡(jiǎn)單容易上手,需要的朋友可以參考下
    2024-01-01
  • Java異常類型及處理詳情

    Java異常類型及處理詳情

    這篇文章主要介紹了Java異常類型及處理, 異常指的是程序在執(zhí)行過(guò)程中,出現(xiàn)了非正常情況,導(dǎo)致了java的jvm停止。感興趣的小伙伴就和小編一起來(lái)學(xué)習(xí)下面文章的具體內(nèi)容吧
    2021-09-09
  • java 嵌套類的詳解及實(shí)例代碼

    java 嵌套類的詳解及實(shí)例代碼

    這篇文章主要介紹了java 嵌套類的詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • vue驗(yàn)證碼組件應(yīng)用實(shí)例

    vue驗(yàn)證碼組件應(yīng)用實(shí)例

    今天小編就為大家分享一篇關(guān)于vue驗(yàn)證碼組件應(yīng)用實(shí)例,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • Spring條件注解@Conditional示例詳解

    Spring條件注解@Conditional示例詳解

    這篇文章主要給大家介紹了關(guān)于Spring條件注解@Conditional的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 如何在Java中優(yōu)雅地使用正則表達(dá)式詳解

    如何在Java中優(yōu)雅地使用正則表達(dá)式詳解

    這篇文章主要給大家介紹了關(guān)于如何在Java中優(yōu)雅地使用正則表達(dá)式的相關(guān)資料,正則表達(dá)式就是一個(gè)字符串,但和普通的字符串不同的是,正則表達(dá)式是對(duì)一組相似字符串的抽象,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-02-02

最新評(píng)論

桐乡市| 莱阳市| 察隅县| 民县| 锡林郭勒盟| 高密市| 上思县| 怀柔区| 灵宝市| 平罗县| 新平| 苏尼特左旗| 内黄县| 江孜县| 砚山县| 宜章县| 永定县| 宜君县| 龙里县| 淮南市| 土默特左旗| 宁德市| 阿勒泰市| 石嘴山市| 南木林县| 运城市| 区。| 石楼县| 吉林省| 绩溪县| 新郑市| 阳曲县| 墨江| 无锡市| 湘阴县| 大方县| 自贡市| 汉寿县| 韩城市| 疏附县| 昆山市|