dockerized 应用程序上的 Spring webClient 调用不支持请求方法 PUT

发布于 2025-01-10 19:21:32 字数 2547 浏览 0 评论 0原文

我制作了一个简单的 SpringBoot 项目,包含 3 个微服务,由 docker-compose.yml 构建。

当我尝试使用 Spring WebClient 调用在微服务之间进行通信时,我收到了

405 不支持请求方法“PUT”http://transactions-ms:8080/sendAccountTransaction

但如果我进行 Postman 调用,则事务微服务是可访问的,并且其他 Web 客户端调用(其他微服务中包含另一个 WebClient)工作正常。

WebClient(URI:http://transactions-ms:8080/sendAccountTransaction)

public ResponseEntity<SavedTransactionRTO> sendAccountTransaction(SendTransactionRequest request) {
        SavedTransactionRTO response = webClient.put()
                .uri(ClientUrl.TRANSACTIONS_URL+ClientEndp.SEND_ACC_TRANSACTION)
                .bodyValue(request)
                .retrieve()
                .bodyToMono(SavedTransactionRTO.class)
                .block();
        return new  ResponseEntity<SavedTransactionRTO>(response, HttpStatus.OK);
    }

控制器方法:

@PutMapping(value = "/sendAccountTransaction", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<SavedTransactionRTO> sendAccountTransaction(@RequestBody SendTransactionRequest request){ 
        SavedTransactionRTO response = transactionService.sendAccountTransaction(request);      
        return new ResponseEntity<SavedTransactionRTO>(response, HttpStatus.OK);
    }

Docker-compose.yml

version: "3"
services:
   transactions-ms:
      image: transactions-ms
      hostname: transactions-ms
      container_name: transactions-ms
      build:
         context: ./transactions-ms
         dockerfile: Dockerfile
      ports:
         - "8080:8080"
              
   accounts-ms:
      image: accounts-ms
      hostname: accounts-ms
      container_name: accounts-ms
      depends_on:
         transactions-ms:
            condition: service_started
      build:
         context: ./accounts-ms
         dockerfile: Dockerfile
      ports:
         - "8081:8081"
      
   customers-ms:
      image: customers-ms
      hostname: customers-ms  
      container_name : customers-ms
      depends_on:
          accounts-ms:
            condition: service_started
      build:
         context: ./customers-ms
         dockerfile: Dockerfile   
      ports:
         - "8082:8082"

DockerFile< /strong>

FROM openjdk:8
EXPOSE 8080 
ADD target/transactions-ms.jar transactions-ms.jar
ENTRYPOINT ["java","-jar","/transactions-ms.jar"]

我已经做了所有可能的尝试,有人有解决方案吗?

I've made a simple SpringBoot project with 3 microservices, built by docker-compose.yml.

When I try to communicate between microservices with a Spring WebClient call, I received

405 Request method 'PUT' not supported http://transactions-ms:8080/sendAccountTransaction

but if I made a Postman call the transactions microservice is reachable and other webclient calls (with another WebClient contained in other microservices) work fine.

WebClient (URI: http://transactions-ms:8080/sendAccountTransaction)

public ResponseEntity<SavedTransactionRTO> sendAccountTransaction(SendTransactionRequest request) {
        SavedTransactionRTO response = webClient.put()
                .uri(ClientUrl.TRANSACTIONS_URL+ClientEndp.SEND_ACC_TRANSACTION)
                .bodyValue(request)
                .retrieve()
                .bodyToMono(SavedTransactionRTO.class)
                .block();
        return new  ResponseEntity<SavedTransactionRTO>(response, HttpStatus.OK);
    }

Controller method:

@PutMapping(value = "/sendAccountTransaction", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<SavedTransactionRTO> sendAccountTransaction(@RequestBody SendTransactionRequest request){ 
        SavedTransactionRTO response = transactionService.sendAccountTransaction(request);      
        return new ResponseEntity<SavedTransactionRTO>(response, HttpStatus.OK);
    }

Docker-compose.yml

version: "3"
services:
   transactions-ms:
      image: transactions-ms
      hostname: transactions-ms
      container_name: transactions-ms
      build:
         context: ./transactions-ms
         dockerfile: Dockerfile
      ports:
         - "8080:8080"
              
   accounts-ms:
      image: accounts-ms
      hostname: accounts-ms
      container_name: accounts-ms
      depends_on:
         transactions-ms:
            condition: service_started
      build:
         context: ./accounts-ms
         dockerfile: Dockerfile
      ports:
         - "8081:8081"
      
   customers-ms:
      image: customers-ms
      hostname: customers-ms  
      container_name : customers-ms
      depends_on:
          accounts-ms:
            condition: service_started
      build:
         context: ./customers-ms
         dockerfile: Dockerfile   
      ports:
         - "8082:8082"

DockerFile

FROM openjdk:8
EXPOSE 8080 
ADD target/transactions-ms.jar transactions-ms.jar
ENTRYPOINT ["java","-jar","/transactions-ms.jar"]

I have made all possible attempts, anyone has a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文