Когда я пытаюсь autwire Spring RestTemplate, я получаю следующую ошибку:
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.
Использование Spring 4 в среде, зависящей от аннотаций.
Мой сервлет диспетчера настроен следующим образом:
<context:component-scan base-package="in.myproject" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
Мой класс, в котором я пытаюсь autwire RestTemplate, выглядит следующим образом:
@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);
}
}