Unable to autowire RestTemplate
I am trying to autowire RestTemplate in my service
but running into the following exception
Error starting ApplicationContext.
To display the conditions report re-run your application with 'debug' enabled.
2021-05-08 23:30:14.792 ERROR 36505 --- [ main]
o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field restTemplate in com.example.service.GeoSerivice
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.
Process finished with exit code 1
1 Answer
3 years ago by Eleven
Do one of the following way
Solution1: Create a new class and use it
private RestTemplate restTemplate = new RestTemplate();
Solution2: Create a bean for RestTemplate
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
3 years ago by Karthik Divi