Spring mvc 我可以编写两个类似的RESTfulWeb服务吗

Spring mvc 我可以编写两个类似的RESTfulWeb服务吗,spring-mvc,Spring Mvc,这个问题是在一次采访中提出的。 我们能用相同的uri和相同的方法类型实现两个相似的端点吗?如果是,dispatcherservlet如何识别端点?如果没有,我们会得到什么例外 例: 不,不可能。如果尝试,将出现以下异常: Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'testController' method public org.springframework.http.Response

这个问题是在一次采访中提出的。 我们能用相同的uri和相同的方法类型实现两个相似的端点吗?如果是,dispatcherservlet如何识别端点?如果没有,我们会得到什么例外

例:


不,不可能。如果尝试,将出现以下异常:

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.

只要测试一下,你就会得到答案
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.