spring boot为什么引入两个mapping会报错
@GetMapping(name = "/hello")
public String hello() {
return "hello";
}
@GetMapping(name = "/hello2")
public String hello2() {
return "hello";
}
当再写@GetMapping(name = "/hello2")的方法时报错。
Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloWord' method
public java.lang.String com.java.HelloWord.hello2()
to {[],methods=[GET]}: There is already 'helloWord' bean method
public java.lang.String com.java.HelloWord.hello() mapped.
除此之外,只写一个mapping @GetMapping(name = "/hello")
http://localhost:8080/hello可以访问到该方法
http://localhost:8080/xxxx也可以访问到该方法