Ambiguous mapping found. Cannot map 'fancyController' bean method

mvc开发时遇到以下问题:

Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'fancyController' bean method
public java.lang.String com.zc.product.controller.FancyController.test()
to {[/product/test]}: There is already 'saleController' bean method
public java.lang.String com.zc.product.controller.SaleController.test() mapped.

原来是在 fancyController 和saleController 中定义了同样的 requestMappting,代码如下:

fancyController 文件中:

@Controller
@RequestMapping("/product")
public class FancyController {
    @RequestMapping(value = "/test")
    @ResponseBody
    public String test() {
        return "{\"status\":\"ok\"}";
    }
}
saleController 文件:

@Controller
@RequestMapping("/product")
public class SaleController { 
    @RequestMapping(value = "/test")
    @ResponseBody
    public String test() {
        return "{\"status\":\"ok\"}";
    }
可以看到
/product/test
重复定义,修改其中一个即可。




你可能感兴趣的:(spring,mvc)