获取带有rest模板的404,该请求可在Postman中使用。我已经尝试过exchage和postForObject。发布的代码是我对postForEntity的最新尝试。仍然得到404。 我尝试访问的端点接受“ application / json”
consumes = MediaType.APPLICATION_JSON_VALUE
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(appConfig
.getAppBaseUrl()
.concat(MESSAGE_URL)
Message message = Message.builder()
.identifier(id)
.status("OK")
.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Message> entity = new HttpEntity<>(message, headers);
try {
restTemplate.postForEntity(uri.toUriString(), entity, Void.class);
} catch (Exception e)
和消息POJO。与服务器@RequestBody完全相同
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Message {
private UUID identifier;
private String status;
private String hostName;
private String createdTime;
}