0

ResponseEntity を使用してテストする次の簡単な Spring MVC テスト メソッドがあります。

@RequestMapping(value = "/", method = RequestMethod.GET, produces= MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>>  home(Locale locale, Model model) {
    Map<String,String> returnMap = new HashMap<String,String>(2);
    returnMap.put("lang1", "Java");
    returnMap.put("lang2", "C++");
    ResponseEntity<Map<String, String>> respEntity = new ResponseEntity<Map<String,String>>(returnMap,  HttpStatus.OK);
    return  respEntity;
}

ResponseEntity が作成され、Eclipse デバッガーで、ResponseEntity オブジェクトの本文、ヘッダー、およびステータス コードがすべて正しいことを確認できますが、ページで次のエラーが発生します。

The resource identified by this request is only capable of generating 
responses with characteristics not acceptable according to the request 
"accept" headers ().

誰かが私が間違っていることを教えてくれたら本当にありがたいです。

4

3 に答える 3

0

次の RequestMapping を使用してみましたか:

@RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
于 2013-04-14T18:29:31.783 に答える
0

この問題が発生したのは、mvc-config.xmlファイルに次のものが欠落していたためです。

<mvc:annotation-driven />
于 2014-06-30T21:41:04.600 に答える