猿问

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也可以访问到该方法

qq_矜我意_1
浏览 1186回答 1
1回答

慕尼黑2545441

sping的配置文件有问题
随时随地看视频慕课网APP

相关分类

Java
我要回答