Tag: resttemplate

无法在Spring启动应用程序中自动装入字段:RestTemplate

在启动过程中运行弹簧引导应用程序时,出现以下exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.client.RestTemplate com.micro.test.controller.TestController.restTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 我在我的TestController中自动assemblyRestTemplate。 我正在使用Maven进行依赖pipe理。 […]

Spring RestTemplate超时

我想为我的Web应用程序使用的其他服务设置连接超时。 我正在使用Spring的RestTemplate与我的服务交谈。 我已经做了一些研究,我已经find并使用下面的XML(在我的应用程序的XML),我相信是用来设置超时。 我正在使用Spring 3.0。 我也看到了同样的问题在这里用RestTemplate的springwebservices超时configuration,但解决scheme似乎并不干净 ,我宁愿设置超时值通过Springconfiguration <bean id="RestOperations" class="org.springframework.web.client.RestTemplate"> <constructor-arg> <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <property name="readTimeout" value="${restURL.connectionTimeout}" /> </bean> </constructor-arg> </bean> 看来无论我设置readTimeout是我得到以下内容: 网线断开:等待约20秒,并报告以下exception: org.springframework.web.client.ResourceAccessExcep tion:I / O错误:没有路由到主机:连接; 嵌套exception是java.net.NoRouteToHostException:没有路由到主机:连接 Url不正确,所以404由rest服务返回:等待大约10秒,并报告以下exception: org.springframework.web.client.HttpClientErrorException:404 Not Found 我的要求要求更短的超时,所以我需要能够改变这些。 任何想法,我做错了什么? 非常感谢。

通过JSON中的RestTemplate发送POST请求

我没有find任何例子来解决我的问题,所以我想问你的帮助。 我不能简单地使用JSON中的RestTemplate对象发送POST请求 每当我得到org.springframework.web.client.HttpClientErrorException:415不支持的媒体types 我以这种方式使用RestTemplate: … restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>(); list.add(new MappingJacksonHttpMessageConverter()); restTemplate.setMessageConverters(list); … Payment payment= new Payment("Aa4bhs"); Payment res = restTemplate.postForObject("http://localhost:8080/aurest/rest/payment", payment, Payment.class); 我的错是什么?

如何在Spring RestTemplate请求上设置“Accept:”标题?

我想设置Accept:的值Accept:在我使用Spring的RestTemplate的RestTemplate 。 这是我的Spring请求处理代码 @RequestMapping( value= "/uom_matrix_save_or_edit", method = RequestMethod.POST, produces="application/json" ) public @ResponseBody ModelMap uomMatrixSaveOrEdit( ModelMap model, @RequestParam("parentId") String parentId ){ model.addAttribute("attributeValues",parentId); return model; } 这里是我的Java REST客户端: public void post(){ MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("parentId", "parentId"); String result = rest.postForObject( url, params, String.class) ; System.out.println(result); } 这适用于我; 我从服务器端得到一个JSONstring。 我的问题是:当我使用RestTemplate时,如何指定Accept:头(例如application/json , application/xml ,…)和请求方法(例如GET […]

用Spring RestTemplate获取JSON对象列表

我有两个问题: 如何使用Spring RestTemplate映射JSON对象的列表。 如何映射嵌套的JSON对象。 我试图通过遵循http://spring.io/guides/gs/consuming-rest/中的教程来使用https://bitpay.com/api/rates 。

Spring RestTemplate – 如何启用完整的debugging/logging请求/响应?

我一直在使用Spring RestTemplate一段时间,当我试图debugging它的请求和响应时,我总是碰壁。 我基本上看到,当我使用curl“verbose”选项打开时看到相同的东西。 例如 : curl -v http://twitter.com/statuses/public_timeline.rss 将显示发送的数据和收到的数据(包括标题,cookie等)。 我已经检查了一些相关的post,如: 如何在Spring RestTemplate中logging响应? 但我还没有设法解决这个问题。 一种方法是实际更改RestTemplate源代码并在其中添加一些额外的日志logging语句,但是我会发现这种方法真的是最后的手段。 应该有一些方法可以告诉Spring Web Client / RestTemplate以更友好的方式logging所有内容。 我的目标是能够用这样的代码来做到这一点: restTemplate.put("http://someurl", objectToPut, urlPathValues); 然后在日志文件或控制台中获得相同types的debugging信息(就像我用curl得到的那样)。 我相信这对于那些使用Spring RestTemplate并且有问题的人来说是非常有用的。 使用curl来debugging你的RestTemplate问题是不行的(在某些情况下)。

使用RestTemplate请求将多部分文件作为POST参数发送

我正在使用Spring 3和RestTemplate。 我基本上有两个应用程序,其中一个必须将值发布到另一个应用程序。 通过rest模板。 当要发布的值是string,它是完美的工作,但是当我必须发布混合和复杂的参数(如MultipartFiles)我得到一个转换器exception。 举个例子,我有这个: App1 – PostController: @RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute UploadDTO pUploadDTO, BindingResult pResult) throws URISyntaxException, IOException { URI uri = new URI("http://localhost:8080/app2/file/receiver"); MultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>(); mvm.add("param1", "TestParameter"); mvm.add("file", pUploadDTO.getFile()); // MultipartFile Map result = restTemplate.postForObject(uri, mvm, Map.class); return "redirect:postupload"; } 另一方面,我有另一个Web应用程序(App2)从App1接收参数。 App2 – ReceiverController @RequestMapping(value […]