码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot 注入 restTemplate

时间:2017-06-26 18:02:59      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:main   lan   需要   run   实例化   app   blog   framework   detail   

转载自:http://blog.csdn.net/liuchuanhong1/article/details/54631080

 

 

package com.chhliu.springboot.restful;  
  
import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
import org.springframework.boot.web.client.RestTemplateBuilder;  
import org.springframework.context.annotation.Bean;  
import org.springframework.web.client.RestTemplate;  
  
@SpringBootApplication  
public class SpringbootRestTemplateApplication {  
    // 启动的时候要注意,由于我们在controller中注入了RestTemplate,所以启动的时候需要实例化该类的一个实例  
    @Autowired  
    private RestTemplateBuilder builder;  
  
        // 使用RestTemplateBuilder来实例化RestTemplate对象,spring默认已经注入了RestTemplateBuilder实例  
    @Bean  
    public RestTemplate restTemplate() {  
        return builder.build();  
    }  
  
    public static void main(String[] args) {  
        SpringApplication.run(SpringbootRestTemplateApplication.class, args);  
    }  
}  

spring boot 注入 restTemplate

标签:main   lan   需要   run   实例化   app   blog   framework   detail   

原文地址:http://www.cnblogs.com/yanqin/p/7081581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!