RestTemplate注入
来源:互联网 发布:怎么用万捷网络验证 编辑:程序博客网 时间:2024/06/06 00:14
Errors you'll see if a RestTemplate
isn't defined
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
or
No qualifying bean of type [org.springframework.web.client.RestTemplate] found
How to define a RestTemplate
via annotations
Depending on which technologies you're using and what versions will influence how you define a RestTemplate
in your @Configuration
class.
Spring >= 4 without Spring Boot
Simply define an @Bean
:
@Beanpublic RestTemplate restTemplate() { return new RestTemplate();}
Spring Boot <= 1.3
No need to define one, Spring Boot automatically defines one for you.
Spring Boot >= 1.4
Spring Boot no longer automatically defines a RestTemplate
but instead defines a RestTemplateBuilder
allowing you more control over the RestTemplate
that gets created. You can inject the RestTemplateBuilder
as an argument in your @Bean
method to create a RestTemplate
:
@Beanpublic RestTemplate restTemplate(RestTemplateBuilder builder) { // Do any additional configuration here return builder.build();}
Using it in your class
@Autowiredprivate RestTemplate restTemplate;
or
@Injectprivate RestTemplate restTemplate;
- RestTemplate注入
- springboot RestTemplate 注入
- RestTemplate
- RestTemplate
- restTemplate
- RestTemplate
- RestTemplate
- RestTemplate 例子
- RestTemplate 调用
- RestTemplate post
- RestTemplate实践
- spring RestTemplate
- RestTemplate实践
- RestTemplate实践
- springboot-restTemplate
- RestTemplate使用
- RestTemplate使用
- httpClient, RestTemplate
- Unity菜单运行cmd,例:用explorer.exe打开某个目录
- 数据结构实验之图论八:欧拉回路
- 【BZOJ1007】水平可见直线(HNOI2008)-栈+凸壳
- linux环境下安装PHP中间件ICE(二)
- Filter实现自动用户自动登录功能(三)
- RestTemplate注入
- jQuery教程 8 AJAX
- MySQL之TIMESTAMP
- js DOM添加删除
- Tensorflow版TextCNN主要代码解析
- 实现可以输入多个圆的半径,求面积、周长
- java基础数据类型转换及基本运算符
- 推荐算法之余弦相似度
- 如何用Html+css3写一个简单的网页