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. [原] XAF 如何将数据库中Byte array图片显示出来

    问题比较简单,直接上代码. private Image _Cover; [Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValue ...

  2. iPad应用开发者的建议

    原文摘自Smashing Magazine<A Dad’s Plea To Developers of iPad Apps For Children> 我花了很长时间为孩子购买和测试iPa ...

  3. halcon摄像机标定

    摄像机标定程序: 注意:E:/calibration_image :为标定图像文件路径       'E:/calibration_description/caltab_123mm.descr:为标定 ...

  4. sql trunc()的使用

    1.TRUNC(for dates)TRUNC函数为指定元素而截去的日期值.其具体的语法格式如下:TRUNC(date[,fmt])其中:date 一个日期值fmt 日期格式,该日期将由指定的元素格式 ...

  5. SQLSERVER复制优化之一《改变包大小》

    SQLSERVER复制优化之一<改变包大小> 自从搭了复制之后以为可以安枕无忧了,谁不知问题接踵而来 这次遇到的问题是丢包,不知道情况的读者可以先看一下我之前写的一篇<SQLSERV ...

  6. [Hyper-V]制作一个干净的操作系统模板

    描述: 在Hyper-V里创建虚拟机的时候,我们可以先来创建一个干净的操作系统,将其制作为操作系统模板,该虚拟机的磁盘文件也将被视作基础磁盘以方便基于它创建差异化磁盘 安装其它虚拟机的时候就可以差异化 ...

  7. SQL SERVER 数据库查询表和字段信息语句

    --数据库中所有表的信息(很强悍的)    SELECT    表名               =   CASE   WHEN   A.COLORDER=1   THEN   D.NAME   EL ...

  8. JAVA开发工具eclipse中@author怎么改

    1:JAVA开发工具eclipse中@author怎么改,开发的时候为了注明版权信息. 用eclipse开发工具默认的是系统用户,那么怎么修改呢 示例如图所示 首先打开Eclipse--->然后 ...

  9. Extjs4中RadioGroup的赋值与取值

    1.定义rg var rg = new Ext.form.RadioGroup({ fieldLabel : "test", items : [{ boxLabel : '每天', ...

  10. 浅入“Block Formatting Context”

    本文主要是针对BFC特性的应用,至于什么是BFC,可以参看MDN的简介: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_fo ...