When I try to autowire Spring RestTemplate
, I am getting following error:
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Using Spring 4 in an annotation driven environment.
My dispatcher servlet is configured as follows:
<context:component-scan base-package="in.myproject" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
My class in which I am trying to autowire RestTemplate
is as follows:
@Service("httpService")
public class HttpServiceImpl implements HttpService {
@Autowired
private RestTemplate restTemplate;
@Override
public void sendUserId(String userId){
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("userId", userId);
map.add("secretKey", "kbhyutu7576465duyfy");
restTemplate.postForObject("http://localhost:8081/api/user", map, null);
}
}