REST APIを使用しようとすると、次のエラーが発生します。
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable
実行されるクライアントコードは次のとおりです。
public static void main(String[] args) {
Car c = getCarById(4);
System.out.println(c);
}
public static @ResponseBody Car getCarById(int id){
return new RestTemplate().getForObject("http://localhost:8080/rest/cars/{id}", Car.class, id);
}
リクエストをマッピングするコントローラーのコードは次のとおりです。
@RequestMapping(value="/cars/{id}", method=RequestMethod.GET, headers = {"Accept=text/html,application/xhtml+xml,application/xml"}, produces="application/xml")
public @ResponseBody Car getCarById(@PathVariable("id") int id){
return carService.getCarById(id);
}
マッパーが正しいタイプへのマッピングを処理する必要があるのに、なぜこのエラー(406-受け入れられない)が発生するのですか?