• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
毛逢芳
博客园    首页    新随笔    联系   管理    订阅  订阅

Eureka-RestTemplate

RestTemplate是spring提供的简单便捷的模板类,用于在java代码里访问restful服务。

其功能与HttpClient类似,但是RestTemplate实现更加优雅,使用更加方便。

RestTemplate的使用步骤
1.定义Bean
编写配置类RestTemplateConfig

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}

2.调用

@Autowired
private RestTemplate restTemplate;
restTemplate.getForObject(url, 类名.class);
posted @ 2020-10-21 16:51  那棵tree看起来生气了  阅读(151)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3