Rest模板404,在Postman中工作

时间:2019-05-17 19:04:11

标签: spring-boot spring-mvc resttemplate

获取带有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;
}

0 个答案:

没有答案