小码问答,有问必答!

SpringBoot不能自动注入RestTemplate

运行springboot项目,出现错误:No qualifying bean of type [org.springframework.web.client.RestTemplate] found

JavaEE

收藏

1个回答

我要回答

  • author
    少尉 2022-02-15 14:13

    在启动类中加入下面的代码就可以解决:

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