2016-07-27 4 views
-2

この質問はインタビューで尋ねられます。 同じURIと同じメソッドタイプの2つの同様のエンドポイントを実装できますか?はいの場合、ディスパッチャ・サーブレットはどのようにエンドポイントを識別しますか?そうでない場合は、どのような例外がありますか?私は2つの同様の穏やかなWebサービスを書くことができます

例:

@RequestMapping(value = "/test", method = RequestMethod.POST) 
    @ResponseBody 
    public ResponseEntity test(){ 
} 

@RequestMapping(value = "/test", method = RequestMethod.POST) 
    @ResponseBody 
    public ResponseEntity test1(){ 
} 
+0

いいえ、これはいいえ、 –

+0

あなたは答えを持っています –

答えて

0

いいえ、それは不可能です。試してみると、次の例外が発生します:

Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'testController' method 
public org.springframework.http.ResponseEntity com.TestController.test1() 
to {[/test],methods=[POST]}: There is already 'testController' bean method 
public org.springframework.http.ResponseEntity com.TestController.test() mapped. 
関連する問題