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

springboot3整合遠(yuǎn)程調(diào)用的過程解析

 更新時(shí)間:2023年06月16日 10:20:44   作者:鴨鴨老板  
遠(yuǎn)程過程調(diào)用主要分為:服務(wù)提供者,服務(wù)消費(fèi)者,通過連接對方服務(wù)器進(jìn)行請求交互,來實(shí)現(xiàn)調(diào)用效果,這篇文章主要介紹了springboot3整合遠(yuǎn)程調(diào)用,需要的朋友可以參考下

一、遠(yuǎn)程調(diào)用

 遠(yuǎn)程過程調(diào)用:主要分為:服務(wù)提供者,服務(wù)消費(fèi)者。通過連接對方服務(wù)器進(jìn)行請求交互,來實(shí)現(xiàn)調(diào)用效果。

二、使用WebClient

@Service
public class WeatherServiceImpl {
    public Mono<String> weather(String city){
        //創(chuàng)建Webclient
        WebClient webClient = WebClient.create();
        HashMap<String, String> map = new HashMap<>();
        map.put("areaCn",city);
        //定義發(fā)送請求的行為
        Mono<String> mono = webClient.get()
                .uri("https://getweather.market.alicloudapi.com/lundear/weather7d?areaCn={areaCn}",map)
                .accept(MediaType.APPLICATION_JSON)//定義響應(yīng)的內(nèi)容類型
                .header("Authorization", "APPCODE 05ed0debacd9479c9788b1a44266eaef")
                .retrieve()
                .bodyToMono(String.class);
        return mono;
    }
}
@RestController
public class WeatherController {
     @Autowired
     private WeatherServiceImpl weatherService;
    @GetMapping("/weather")
    public Mono<String> weather(@RequestParam("city") String city){
        return weatherService.weather(city);
    }
    @GetMapping("/hello")
    public String hello(){
        return "你好";
    }
}

三、使用HTTP Interface

public interface WeatherInterface {
    @GetExchange(url = "/lundear/weather7d",accept = "application/json")
    Mono<String> getWeather(@RequestParam("areaCn") String city,
                    @RequestHeader("Authorization") String auth);
}
 public Mono<String> weather1(String city){
        //1、創(chuàng)建客戶端
        WebClient client = WebClient.builder()
                .baseUrl("https://getweather.market.alicloudapi.com")
                .codecs(clientCodecConfigurer -> {
                    clientCodecConfigurer
                            .defaultCodecs()
                            .maxInMemorySize(256*1024*1024);
                    //響應(yīng)數(shù)據(jù)量太大有可能會(huì)超出BufferSize,所以這里設(shè)置的大一點(diǎn)
                }).build();
        //2、創(chuàng)建工廠
        HttpServiceProxyFactory factory = HttpServiceProxyFactory
                .builder(WebClientAdapter.forClient(client)).build();
        //3、獲取代理對象
        WeatherInterface weatherInterface = factory.createClient(WeatherInterface.class);
        Mono<String> weather = weatherInterface.getWeather(city, "APPCODE 05ed0debacd9479c9788b1a44266eaef");
        return  weather;
    }

3.1、抽取方法

在配置文件中配置appcode

config配置類 

@Configuration
public class RPCConfig {
    @Value("${aliyu.appcode}")
    private String appCode;
    @Bean
    HttpServiceProxyFactory factory(){
        //1、創(chuàng)建客戶端
        WebClient client = WebClient.builder()
                .defaultHeader("Authorization","APPCODE "+ appCode)
                .codecs(clientCodecConfigurer -> {
                    clientCodecConfigurer
                            .defaultCodecs()
                            .maxInMemorySize(256*1024*1024);
                    //響應(yīng)數(shù)據(jù)量太大有可能會(huì)超出BufferSize,所以這里設(shè)置的大一點(diǎn)
                }).build();
        //2、創(chuàng)建工廠
        HttpServiceProxyFactory factory = HttpServiceProxyFactory
                .builder(WebClientAdapter.forClient(client)).build();
        return factory;
    }
    @Bean
    WeatherInterface weatherInterface(HttpServiceProxyFactory httpServiceProxyFactory){
        //3、獲取代理對象
        WeatherInterface weatherInterface = httpServiceProxyFactory.createClient(WeatherInterface.class);
        return weatherInterface;
    }
    @Bean
    AlicloudAPIService alicloudAPIService(HttpServiceProxyFactory httpServiceProxyFactory){
        AlicloudAPIService alicloudAPIService = httpServiceProxyFactory.createClient(AlicloudAPIService.class);
        return alicloudAPIService;
    }
}
public interface AlicloudAPIService {
    @GetExchange(url = "https://wuliu.market.alicloudapi.com/kdi",accept = "application/json")
    Mono<String> getWeather(@RequestParam("no") String no);
}
public interface WeatherInterface {
    @GetExchange(url = "https://getweather.market.alicloudapi.com/lundear/weather7d",accept = "application/json")
    Mono<String> getWeather(@RequestParam("areaCn") String city);
}
 @Autowired
    private WeatherInterface weatherInterface;
    @Autowired
    private AlicloudAPIService alicloudAPIService;
    public Mono<String> weather1(String city){
        Mono<String> weather = weatherInterface.getWeather(city);
        return  weather;
    }
    public Mono<String> alicloudAPI(String no){
        Mono<String> weather = alicloudAPIService.getWeather(no);
        return weather;
    }
@RestController
public class WeatherController {
     @Autowired
     private WeatherServiceImpl weatherService;
    @GetMapping("/weather")
    public Mono<String> weather(@RequestParam("city") String city){
        //return weatherService.weather(city);
        return weatherService.weather1(city);
    }
    @GetMapping("/alicloudAPI")
    public Mono<String> alicloudAPI(@RequestParam("no") String no){
        return weatherService.alicloudAPI(no);
    }
}

到此這篇關(guān)于springboot3整合遠(yuǎn)程調(diào)用的文章就介紹到這了,更多相關(guān)springboot3遠(yuǎn)程調(diào)用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java解析JSON數(shù)據(jù)時(shí)報(bào)錯(cuò)問題解決方案

    Java解析JSON數(shù)據(jù)時(shí)報(bào)錯(cuò)問題解決方案

    這篇文章主要介紹了Java解析JSON數(shù)據(jù)時(shí)報(bào)錯(cuò)問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Java實(shí)現(xiàn)文件監(jiān)控器FileMonitor的實(shí)例代碼

    Java實(shí)現(xiàn)文件監(jiān)控器FileMonitor的實(shí)例代碼

    這篇文章主要介紹了Java實(shí)現(xiàn)文件監(jiān)控器FileMonitor的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • idea 2023.1字體設(shè)置及自動(dòng)調(diào)整大小的圖文教程

    idea 2023.1字體設(shè)置及自動(dòng)調(diào)整大小的圖文教程

    這篇文章主要介紹了idea 2023.1字體設(shè)置及自動(dòng)調(diào)整大小的教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • 使用Java操作TensorFlow的方法

    使用Java操作TensorFlow的方法

    TensorFlow是一個(gè)功能強(qiáng)大且廣泛使用的框架,它不斷得到改進(jìn),并最近被引入新語言包括Java和JavaScript,這篇文章主要介紹了如何使用Java操作TensorFlow,需要的朋友可以參考下
    2023-05-05
  • Java+JFrame實(shí)現(xiàn)貪吃蛇小游戲

    Java+JFrame實(shí)現(xiàn)貪吃蛇小游戲

    這篇文章主要為大家詳細(xì)介紹了Java+JFrame實(shí)現(xiàn)貪吃蛇小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Java實(shí)現(xiàn)List與數(shù)組互轉(zhuǎn)(Arrays.asList與Collectors.toList)的兩種方法

    Java實(shí)現(xiàn)List與數(shù)組互轉(zhuǎn)(Arrays.asList與Collectors.toList)的兩種方法

    在 Java 編程中,List 和數(shù)組(Array)是兩種常用的數(shù)據(jù)結(jié)構(gòu),本文將深入探討 List 與數(shù)組之間的相互轉(zhuǎn)換,重點(diǎn)介紹 Arrays.asList 和 Collectors.toList 這兩種常用且重要的方法,并分析它們的特點(diǎn)、適用場景及注意事項(xiàng),需要的朋友可以參考下
    2026-01-01
  • Java實(shí)現(xiàn)JSON與XML相互轉(zhuǎn)換的簡明教程

    Java實(shí)現(xiàn)JSON與XML相互轉(zhuǎn)換的簡明教程

    Java實(shí)現(xiàn)復(fù)雜數(shù)據(jù)結(jié)構(gòu)(如嵌套對象、數(shù)組)在 JSON 與 XML 之間的相互轉(zhuǎn)換,可以使用 Jackson 和 Jackson XML 擴(kuò)展庫來完成,Jackson 是一個(gè)流行的 JSON 處理庫,通過 Jackson 的 XML 擴(kuò)展庫,可以實(shí)現(xiàn) JSON 和 XML 之間的轉(zhuǎn)換,需要的朋友可以參考下
    2024-08-08
  • IntelliJ IDEA下自動(dòng)生成Hibernate映射文件以及實(shí)體類

    IntelliJ IDEA下自動(dòng)生成Hibernate映射文件以及實(shí)體類

    這篇文章主要介紹了IntelliJ IDEA下自動(dòng)生成Hibernate映射文件以及實(shí)體類,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • 解決springboot遇到autowire注入為null的問題

    解決springboot遇到autowire注入為null的問題

    這篇文章主要介紹了解決springboot遇到autowire注入為null的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Spring @ConditionalOnMissingBean 注解的主要作用解析

    Spring @ConditionalOnMissingBean 注解的主要作用解析

    @ConditionalOnMissingBean是Spring Boot中用于條件化配置的注解,確保只有在指定Bean不存在時(shí)才創(chuàng)建,它在自動(dòng)配置中廣泛應(yīng)用,提供默認(rèn)配置并允許用戶自定義Bean,本文給大家介紹Spring @ConditionalOnMissingBean注解的作用,感興趣的朋友一起看看吧
    2026-01-01

最新評論

新建县| 金门县| 武安市| 海林市| 双城市| 安丘市| 祁阳县| 孟州市| 扶沟县| 平和县| 深州市| 康平县| 曲麻莱县| 永济市| 皮山县| 奉化市| 广河县| 瑞丽市| 延津县| 灵台县| 托克逊县| 永川市| 临桂县| 应用必备| 岳阳市| 乳山市| 永州市| 石河子市| 庐江县| 聊城市| 商水县| 方城县| 温宿县| 昭苏县| 女性| 巴中市| 崇州市| 平远县| 连平县| 分宜县| 上栗县|