亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot調(diào)用SOAP接口全流程(含多服務(wù)配置)

 更新時(shí)間:2025年06月06日 10:32:57   作者:Jamie Chyi  
本文主要介紹了SpringBoot調(diào)用SOAP接口全流程(含多服務(wù)配置),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

在現(xiàn)代系統(tǒng)中,雖然 REST 接口廣泛使用,但一些傳統(tǒng)平臺(tái)仍使用 SOAP 協(xié)議。本文將手把手教你如何在 Spring Boot 項(xiàng)目中優(yōu)雅集成并調(diào)用 SOAP 接口,支持多個(gè)服務(wù)配置、注解調(diào)用、自定義參數(shù)傳遞等。

?? 1. 引入 Maven 依賴

		<dependency>
			<groupId>org.springframework.ws</groupId>
			<artifactId>spring-ws-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
		</dependency>

?? 2. 使用 wsimport 命令生成客戶端代碼

打開終端,執(zhí)行以下命令(替換為實(shí)際的 WSDL 地址):

wsimport -keep -p com.example.soapclient https://xxx.cn/tp_core/xxx/MsgWebService?wsdl

?? 3. 編寫配置類(支持多服務(wù))

@Configuration
public class SoapClientConfig {
    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // 設(shè)置生成的SOAP類所在的包名,這里替換成實(shí)際的包路徑
        marshaller.setContextPath("com.ly.cloud.common.soap");
        return marshaller;
    }

    @Bean
    public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setDefaultUri("https://xxx/xxx/service/MsgWebService");
        // 配置 marshaller 和 unmarshaller
        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.setUnmarshaller(marshaller);
        return webServiceTemplate;
    }
}

?? 4. 編寫調(diào)用 Service(JSON 作為入?yún)ⅲ?/h2>

這里只需要傳一個(gè)String類型的json入?yún)⒆址?,即可拿到調(diào)用結(jié)果。實(shí)際場(chǎng)景可以結(jié)合Controller實(shí)現(xiàn)

@Service
public class MySoapService{
    @Autowired
    private WebServiceTemplate webServiceTemplate;

    public String callSoapService(String message) {
        Map<String,Object> map = new HashMap<>();
        map.put("OTHER_PK_ID", "");
        String jsonString = JSONObject.toJSONString(map);
        // 入?yún)son字符串
        AddMessage addMessage = new AddMessage();
        addMessage.setIn0(jsonString);
        System.out.println(jsonString);
        AddMessageResponse response = (AddMessageResponse) webServiceTemplate.marshalSendAndReceive(addMessage);
        // 調(diào)用結(jié)果
        return response.getOut();
    }
    
}

?? 5. 多服務(wù)擴(kuò)展配置(可選)

如果你需要調(diào)用多個(gè) SOAP 服務(wù)接口,可以配置多個(gè) WebServiceTemplate 和 Marshaller

@Configuration
public class SoapClientConfig {
    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // 設(shè)置生成的SOAP類所在的包名,這里替換成實(shí)際的包路徑
        marshaller.setContextPath("com.ly.cloud.common.soap");
        return marshaller;
    }

    @Bean
    public Jaxb2Marshaller marshaller2() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // 配置第二個(gè)包路徑 com.ly.cloud.common.soap.app,對(duì)應(yīng)第二個(gè) namespace
        marshaller.setContextPath("com.ly.cloud.common.soap.app");
        return marshaller;
    }
    @Bean
    public Jaxb2Marshaller marshaller3() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // 配置第三個(gè)個(gè)包路徑 com.ly.cloud.common.soap.email,對(duì)應(yīng)第二個(gè) namespace
        marshaller.setContextPath("com.ly.cloud.common.soap.email");
        return marshaller;
    }

    @Bean
    public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setDefaultUri("https://xxx/tp_core/service/MsgWebService");
        // 配置 marshaller 和 unmarshaller
        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.setUnmarshaller(marshaller);
        return webServiceTemplate;
    }

    @Bean
    public WebServiceTemplate webServiceTemplate2(Jaxb2Marshaller marshaller2) {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setDefaultUri("https://xxx/mp/service/AppService");
        // 配置 marshaller 和 unmarshaller
        webServiceTemplate.setMarshaller(marshaller2);
        webServiceTemplate.setUnmarshaller(marshaller2);
        return webServiceTemplate;
    }
    @Bean
    public WebServiceTemplate webServiceTemplate3(Jaxb2Marshaller marshaller3) {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setDefaultUri("https://xxx/mp/service/EmailService");
        // 配置 marshaller 和 unmarshaller
        webServiceTemplate.setMarshaller(marshaller3);
        webServiceTemplate.setUnmarshaller(marshaller3);
        return webServiceTemplate;
    }
}

使用的過(guò)程中,分別注入對(duì)應(yīng)的即可。

? 總結(jié)

本文完整展示了 Spring Boot 如何調(diào)用 SOAP 接口的全過(guò)程,涵蓋:

  • wsimport 生成代碼

  • Spring 配置與依賴注入

  • JSON 參數(shù)封裝與發(fā)送

  • 多服務(wù)并存配置

SOAP 雖老,實(shí)戰(zhàn)依舊有用

到此這篇關(guān)于SpringBoot調(diào)用SOAP接口全流程(含多服務(wù)配置)的文章就介紹到這了,更多相關(guān)SpringBoot調(diào)用SOAP接口內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 微服務(wù)Spring?Cloud?Alibaba?的介紹及主要功能詳解

    微服務(wù)Spring?Cloud?Alibaba?的介紹及主要功能詳解

    Spring?Cloud?是一個(gè)通用的微服務(wù)框架,適合于多種環(huán)境下的開發(fā),而?Spring?Cloud?Alibaba?則是為阿里巴巴技術(shù)棧量身定制的解決方案,本文給大家介紹Spring?Cloud?Alibaba?的介紹及主要功能,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • Java實(shí)現(xiàn)人機(jī)猜拳游戲

    Java實(shí)現(xiàn)人機(jī)猜拳游戲

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)人機(jī)猜拳游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • idea運(yùn)行java項(xiàng)目main方法報(bào)build failure錯(cuò)誤的解決方法

    idea運(yùn)行java項(xiàng)目main方法報(bào)build failure錯(cuò)誤的解決方法

    當(dāng)在使用 IntelliJ IDEA 運(yùn)行 Java 項(xiàng)目的 main 方法時(shí)遇到 "Build Failure" 錯(cuò)誤,這通常意味著在項(xiàng)目的構(gòu)建過(guò)程中遇到了問(wèn)題,以下是一些詳細(xì)的解決步驟,以及一個(gè)簡(jiǎn)單的代碼示例,用于展示如何確保 Java 程序可以成功構(gòu)建和運(yùn)行,需要的朋友可以參考下
    2024-09-09
  • 如何使用java修改文件所有者及其權(quán)限

    如何使用java修改文件所有者及其權(quán)限

    這篇文章主要介紹了如何使用java修改文件所有者及其權(quán)限,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • java中的PriorityQueue類過(guò)程詳解

    java中的PriorityQueue類過(guò)程詳解

    這篇文章主要介紹了java中的PriorityQueue類,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • SpringBoot bean加載順序怎樣查看(源碼解讀)

    SpringBoot bean加載順序怎樣查看(源碼解讀)

    這篇文章主要介紹了SpringBoot bean加載順序怎樣查看(源碼解讀)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java 使用keytool創(chuàng)建CA證書的操作

    Java 使用keytool創(chuàng)建CA證書的操作

    這篇文章主要介紹了Java 使用keytool創(chuàng)建CA證書的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • Java使用正則表達(dá)式提取XML節(jié)點(diǎn)內(nèi)容的方法示例

    Java使用正則表達(dá)式提取XML節(jié)點(diǎn)內(nèi)容的方法示例

    這篇文章主要介紹了Java使用正則表達(dá)式提取XML節(jié)點(diǎn)內(nèi)容的方法,結(jié)合具體實(shí)例形式分析了java針對(duì)xml格式字符串的正則匹配相關(guān)操作技巧,需要的朋友可以參考下
    2017-08-08
  • java Hibernate 一對(duì)多自身關(guān)聯(lián)問(wèn)題

    java Hibernate 一對(duì)多自身關(guān)聯(lián)問(wèn)題

    formBean在提交表單的時(shí)候,域中數(shù)據(jù)庫(kù)在下一次中仍然保留引起的,struts formBean 默認(rèn)的scope為session,手動(dòng)設(shè)置為request,就好了
    2008-07-07
  • Java8中的Stream?流實(shí)踐操作

    Java8中的Stream?流實(shí)踐操作

    這篇文章主要介紹了Java8中的Stream?流實(shí)踐操作,Stream?是?java8?中處理集合的抽象概念,可以執(zhí)行非常復(fù)雜的查詢、過(guò)濾和映射數(shù)據(jù)等操作,下文更多相關(guān)資料介紹,需要的朋友可以參考一下
    2022-05-05

最新評(píng)論