Jur*_*raj 9 rest spring controller ambiguous-call spring-boot
嗨,我的Sample中有一个简单的RestController:
@RestController
public class PersonController {
@RequestMapping(name = "/getName", method = GET)
public String getName() {
return "MyName";
}
@RequestMapping(name = "/getNumber", method = GET)
public Double getNumber(){
return new Double(0.0);
}
}
Run Code Online (Sandbox Code Playgroud)
我有SampleController用于启动SpringBoot:
@SpringBootApplication
@Controller
public class SampleController {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行SampleCotroller时,会发生以下异常:
Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'personController' bean method
public java.lang.Double com.web.communication.PersonController.getNumber()
to {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'personController' bean method
public java.lang.String com.web.communication.PersonController.getName() mapped.
Run Code Online (Sandbox Code Playgroud)
问题出在哪里?一个RestController中不能有更多的RequestMappings?
非常感谢您的回复
Roh*_*ain 27
您必须使用value
属性来定义映射.您name
现在使用过,它只是为映射提供了一个名称,但根本没有定义任何映射.所以目前你的方法都是未映射的(在这种情况下,两者都映射到相同的路径).将方法更改为:
@RequestMapping(value = "/getName", method = GET)
public String getName() {
return "MyName";
}
@RequestMapping(value = "/getNumber", method = GET)
public Double getNumber(){
return new Double(0.0);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6763 次 |
最近记录: |