多个RestTemplate对象示例
@Configuration
public class MyConfiguration { @LoadBalanced
5 @Bean
RestTemplate loadBalanced() {
return new RestTemplate();
} @Primary
11 @Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
} public class MyClass {
@Autowired
private RestTemplate restTemplate; @Autowired
@LoadBalanced
private RestTemplate loadBalanced; public String doOtherStuff() {
return loadBalanced.getForObject("http://stores/stores", String.class);
} public String doStuff() {
return restTemplate.getForObject("http://example.com", String.class);
}
}
如果发现报这个错误
java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89
试试注入RestOperations或者加上spring.aop.proxyTargetClass=true
多个RestTemplate对象示例的更多相关文章
- RestTemplate对象,进行get和post简单用法
如果只是针对纯Rest接口处理的话,我们可以使用restTemplate对象来操作,简单方便,可以不需要手写httpClient代码了. 我们看下基本的用法,如下: 1.getForObject cl ...
- js解析json读取List中的实体对象示例
1.由后台action 传给前台是需要将map 转成json格式 复制代码代码如下: Map<String, List> resultMap: JSONObject json = JSON ...
- Node.js 使用jQuery取得Nodejs http服务端返回的JSON对象示例
server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http" ...
- vue方法中传递dom对象示例
<div id="app"> <input type="text" v-on:keyup="onlyNum($event)" ...
- php 对象示例
<?php header("content-type:text/html; charset=utf-8"); error_reporting(E_ALL); class My ...
- RestTemplate对象的使用
- 二:C#对象、集合、DataTable与Json内容互转示例;
导航目录: Newtonsoft.Json 概述 一:Newtonsoft.Json 支持序列化与反序列化的.net 对象类型: 二:C#对象.集合.DataTable与Json内容互转示例: ...
- RestTemplate实践
什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效 ...
- Spring RestTemplate介绍
http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...
随机推荐
- android自定义viewgroup初步之一----抽屉菜单
转载请注明出处 http://blog.csdn.net/wingichoy/article/details/47832151 几天前在慕课网上看到鸿洋老师的 自定义卫星菜单,感觉很有意思,于是看完视 ...
- 【Android 应用开发】OpenGL ES 2.0 -- 制作 3D 彩色旋转三角形 - 顶点着色器 片元着色器 使用详解
最近开始关注OpenGL ES 2.0 这是真正意义上的理解的第一个3D程序 , 从零开始学习 . 案例下载地址 : http://download.csdn.net/detail/han120201 ...
- 加载SpriteBuilder中的scene为何不能带后缀
我们在Xcode中切换SpriteBuilder中的scene时,一般使用的是如下代码: -(void)exitButtonPressed:(CCControl*)sender{ CCLOG(@&qu ...
- iOS8 UILocalNotification 增加启动授权
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/46810357 ...
- OpenCV OpenGL手写字符识别
另外一篇文章地址:这个比较详细,但是程序略显简单,现在这个程序是比较复杂的 http://blog.csdn.net/wangyaninglm/article/details/17091901 整个项 ...
- java中split(regex)使用中要注意的问题:正则表达式
比如我在项目中遇到的(,),.,|,*等等类的符号: String area="(30.13206313822174, 120.4156494140625)(29.8763738070713 ...
- 三、编辑 Update set
文档目录 开始使用 初始化查询实例: LambdaToSql.SqlClient DB = new LambdaToSql.SqlClient(); 更新单个实体对象,必须有主键Guid var e ...
- javascript—Mach的一些常用方法
1.Math.random():返回 0 ~ 1 之间的随机数. 2.Math.round():四舍五入取整. 3.Math.ceil():向上取整; 例如:a=1.2,b=5.8; ...
- winform 写App.config配置文件——IT轮子系列(八)
前言 在winform项目中,常常需要读app.config文件.如: var version = System.Configuration.ConfigurationManager.AppSetti ...
- DB2常见问题
15.1实例常见问题和诊断案例 1.实例无法启动问题 db2nodes.cfg文件,主要是为了数据库分区设计的.如果实例无法启动,要检查db2nodes.cfg,看配置是否正常.db2systm实例配 ...