1. 程式人生 > >There is already 'xxxxx' bean method

There is already 'xxxxx' bean method

今天寫程式碼的時候遇到了如下問題

2017-04-26 11:17:02.198  WARN 6411 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 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 'demoController' method public void cn.peakline.controller
.DemoController.checkCode(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException to {[/demo/checkCode]}:
There is already 'demoController' bean method public void cn.peakline.controller.DemoController.getCode(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
mapped.

經過檢查,是因為controller裡有了多個相同的請求{[/demo/checkCode]},修改或者刪除其他方法,確定只有一個請求名稱即可