解决:required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.与扩展

错误描述:

Description:

Field restTemplate in com.tky.bim.basedata.service.impl.RelationV1Update required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.

描述说没有找到restTemplate,说明restTemplate没有注入到spring容器中去,我们需要手动把它注入进来,在启动类上注入


  /**
   * @Description: 手动注入RestTemplate
   *
   * <p>启动报错:找不到RestTemplate
   *
   * @auther: zpq
   * @date: 2020/11/5 4:13 下午
   */
  @Bean
  public RestTemplate restTemplate() {
    return new RestTemplate();
  }

这样再重新启动就可以了。

扩展

Spring RestTemplate 介绍与使用


版权声明:本文为qq_42094345原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。