报错代码:
很低级的错误,代码是copy过来的,但是启动类是我自己手动创建的,导致没有观察到需要创建一个bean
Description:
Field restTemplate in com.changgou.oauth.service.impl.AuthServiceImpl 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.
报错位置:

解决方法:
只需要简单的简单地定义一个@Bean:

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
本文解决了一个常见的Spring Boot应用问题,即在AuthService中因缺少RestTemplate Bean而引发的异常。通过在配置类中简单添加@Bean注解的方法,成功解决了依赖注入失败的问题。
2427

被折叠的 条评论
为什么被折叠?



