i realize that something wired goes on with a project i try to create. I'm using the RestTemplate. And i'm trying to connect with a server and retrieve data. All went good until the time i decide to broke my program in more than one controller classes. Look what i did. In each one of these new classes i insert at each one of them:
RestTemplate restTemplate= new RestTemplate();
In order to retrieve data i'm using the JAXB annotations only(for data binding) and i can retrieve whatever i want. But when i'm trying to execute this line of code in the new class:
ResponseEntity<AClass> result = restTemplate.exchange("url",
HttpMethod.GET, entity, AClass.class);
I'm taking this exception: RestClientException "Could not extract response: no suitable HttpMessageConverter found for response type [AClass] and content type [application/xml]"
If i put it back in the previous class can be executed without problem. Really i don't understand why. Probably because i'm using in the new class a new RestTemplate.I try to declare different RestTemplates and also to declare this way:@Autowired but the problem remains. Should i declare something new in the dispatcher servlet?Moreover can i call in many classes the object restTemplate(RestTemplate restTemplate=new RestTemplate()). Should i declare it in a specific class and call it from there? What should i do?I expect your propositions.