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也可以訪問到該方法
2018-01-09
Spring boot是java后臺代碼的自動配置