dockerized 应用程序上的 Spring webClient 调用不支持请求方法 PUT
我制作了一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论