본문 바로가기
clip

[Spring] java.lang.IllegalStateException: Ambiguous mapping. Cannot map '***' method / requestMapping이 충돌하는 경우

by fien 2021. 6. 29.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/C:/Users/user/.gradle/caches/modules-2/files-2.1/io.springfox/springfox-spring-web/2.9.2/ed2ed714a6cba8804d00f80f0534901e4c7a3211/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'MemberController' method

Controller에서 RequestMapping이 충돌하는 경우 위와 같은 에러가 발생한다.

동일한 Get 메소드에 동일한 value 값이 지정되어 있어 핸들러 매핑이 불가능하다.

요청 메소드(GET, POST 등..)가 다르거나 value(uri)가 다르면 충돌이 발생하지 않는다.

반복작업을 하다보면 나오는 실수...

@RestController
@RequestMapping("/member")
public class MemberController {

  @GetMapping(value = "")
  public ResponseEntity getMember(@RequestParam(required = true) String memId) {
    ...
  }

  @GetMapping(value = "")
  public ResponseEntity getMember2(@RequestParam(required = true) String memId) {
    ...
  }
}

댓글