问题:
在SpringBoot中,某个类使用到了RestTemaplte对象.然后爆红.
运行时出现了如下异常:
Consider defining a bean of type ‘org.springframework.web.client.RestTemplate’ in your configuration
这是因为在springboot1.4以及以后的版本中,需要手动创建一个RestTemplate的配置.
解决方案:
新建一个配置类,通过Bean注解对RestTemplate对象进行配置.
package com.xuecheng.test.freemarker.config;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
解决参考:https://blog.csdn.net/feinifi/article/details/82692384
https://blog.csdn.net/danielinbiti/article/details/78690638