I make a put request

RestTemplate restTemplate = new RestTemplate();
restTemplate.put(new URI("http://localhost:8080/test"), dto);

which successfully hits the rest endpoint

@RequestMapping(value = "/test", method=RequestMethod.PUT)
public void test123(@RequestBody DTO dto) {
System.out.println("phone:"+dto.getPhone());
}

but the "put" method on the client throws exception, even though the server is hit successfully and I don't expect return value.

Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 404 Not Found
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:589)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:547)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:518)
at org.springframework.web.client.RestTemplate.put(RestTemplate.java:394)
at com.my.Main.main(Main.java:45)

查看连接路径是否正确。

Why restTemplate.put() throws “HttpClientErrorException: 404 Not Found”的更多相关文章

  1. 使用RestTemplate请求报出HttpClientErrorException异常并获取不到返回body数据

    描述: 使用RestTemplate请求url,由于Token等验证信息参数失效,报出 401 HttpClientErrorException异常.并且获取不到body消息体的错误信息.然而post ...

  2. 自定义 RestTemplate 异常处理 (转)

    转自:https://ethendev.github.io/2018/11/06/RestTemplate-error-handler/ 一些 API 的报错信息通过 Response 的 body返 ...

  3. RestTemplate实践(及遇到的问题)

    在微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.我们可以使用JDK原生的URLConnection.Apache的Http Client.Netty的异步 ...

  4. TabWidget/TabHost的两种使用方法

    1.概念 盛放Tab的容器就是TabHost.TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab ...

  5. SpringMvc接口中转设计(策略+模板方法)

    一.前言 最近带着两个兄弟做支付宝小程序后端相关的开发,小程序首页涉及到很多查询的服务.小程序后端服务在我司属于互联网域,相关的查询服务已经在核心域存在了,查询这块所要做的工作就是做接口中转.参考了微 ...

  6. java实现跳过证书校验

    /** * 跳过证书效验的sslcontext * @return * @throws Exception */ private static SSLContext createIgnoreVerif ...

  7. 精讲RestTemplate第7篇-自定义请求失败异常处理

    本文是精讲RestTemplate第7篇,前篇的blog访问地址如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层H ...

  8. 使用Spring的RestTemplate进行接口调用

    引自:http://www.zimug.com/ 1.常见的http服务的通信方式 经常使用的方式有HttpClient.OkHttp.RestTemplate.其中RestTemplate是一种更优 ...

  9. RestTemplate实践

    什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效 ...

随机推荐

  1. Fix network adapter not present problem in cloned CentOS

    (You can find a lot of articles on this from the internet. I just put it here for my own record.) It ...

  2. centos 安装PGSQL

    centos 安装PGSQLCentOS下yum安装PostgreSQL目录 1 Configure YUM repository2 Install PGDG RPM file3 Install Po ...

  3. orcale 匿名代码块

    declare cursor readflow_cur is select * from od_readflow t where t.flowid is null; l_emp od_readflow ...

  4. PHP文件相关

    <?php class FileDemo { function Test() { print __FILE__."<br/>"; //返回文件完整路径,如 E:/ ...

  5. Orchard Oracle 支持

    Orchard v1.7发布了,非常不错的一个升级,为了支持Oracle,基本上和v1.6版差不多,只是工作流相关的表有名字超长问题,改个名就可以了,作了个patch包,发布在: https://or ...

  6. Dynamic CRM 2013学习笔记(十一)利用Javascript实现子表合计(汇总,求和)功能

    我们经常有这样一种需求,子表里新加或修改一数值后,要马上在主表里把它们的和显示在主表上.如果用插件来实现,可以实现求和,但页面上还要刷新一下才能显示正确.这时就考虑到用JS来实现这一功能,并自动刷新页 ...

  7. 【Leetcode】【Medium】word search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  8. libevent (一) socket属性设置与初始化操作

    socket属性设置与初始化操作 libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名 ...

  9. FreeIconMaker - 在线创建免费和时尚的图标

    在设计一个网站或 Web 应用程序时,你不能否认网页设计工具的重要性,这些工具有助于简化您的任务和完成您的项目.FreeIconMaker.com 是一个免费的在线图标制作工具,您也可以创建自己的模板 ...

  10. 两两组合覆盖测试用例设计工具:PICT

    两两组合覆盖测试用例设计工具:PICT 2016-08-31 目录 1 成对测试简介2 PICT使用  2.1 安装 PICT  2.2 使用PICT3 PICT算法  3.1 准备阶段  3.2 产 ...