I had a problem while testing a Spring controller. I use the @WebMvcTest annotation in my test class. When I run the test, I get this error: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder' is available
I use RestTemplate for other classes in my project, so I defined a bean in my main class:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
For it to work, I have to define my restTemplate bean as follows:
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
Is this a problem with the @WebMvcTest annotation or am I missing something?
thank
source
share