org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]: {public com.ca.bean.ErrorWrapper com.ca.exceptionHandler.RestResponseEntityExceptionHandler.handleMethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException), public final org.springframework.http.ResponseEntity org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest)}

Stack Overflow | Krishna | 5 months ago
  1. 0

    Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]

    Stack Overflow | 5 months ago | Krishna
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]: {public com.ca.bean.ErrorWrapper com.ca.exceptionHandler.RestResponseEntityExceptionHandler.handleMethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException), public final org.springframework.http.ResponseEntity org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest)}
  2. 0

    Ambiguous @ExceptionHandler method mapped

    Stack Overflow | 4 years ago | Dangling Piyush
    java.lang.IllegalStateException: Ambiguous @ExceptionHandler method mapped for [class com.hcdc.coedp.safe.exception.GenericException]: {public org.springframework.web.servlet.ModelAndView com.hcdc.coedp.safe.controller.UserController.list(java.util.Map,com.hcdc.coedp.safe.domain.User,javax.servlet.http.HttpServletRequest), public org.springframework.web.servlet.ModelAndView com.hcdc.coedp.safe.controller.UserController.create(com.hcdc.coedp.safe.domain.PreRegister,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)}.
  3. 0

    Let's start with the reproducing sample first. {noformat} $ git clone https://github.com/spring-projects/spring-data-examples $ cd spring-data-examples/rest/starbucks $ mvn spring-boot:run $ curl -v -X HEAD http://localhost:8080/api/stores > HEAD /api/stores HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 500 Internal Server Error < Server: Apache-Coyote/1.1 < Content-Type: application/json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Sat, 16 Apr 2016 12:37:59 GMT < Connection: close {noformat} The server produces the following exception: {noformat} java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException} at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361) ~[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1] at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] at org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] … {noformat} I was caught by surprise to see that as the two methods mentioned — [{{RepositoryEntityController.headCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L160] and [{{RepositoryEntityController. getCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L193] are considered ambiguous as they actually declare request mappings for different HTTP methods. {{getCollectionResource}} clearly maps to {{GET}}, not {{HEAD}}. On Spring 4.2 this works as expected as you can see by downgrading the example to Spring Boot 1.4.0.M1 (by tweaking the version number of the Boot parent in the root project's POM).

    Spring JIRA | 8 months ago | Oliver Gierke
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Let's start with the reproducing sample first. {noformat} $ git clone https://github.com/spring-projects/spring-data-examples $ cd spring-data-examples/rest/starbucks $ mvn spring-boot:run $ curl -v -X HEAD http://localhost:8080/api/stores > HEAD /api/stores HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 500 Internal Server Error < Server: Apache-Coyote/1.1 < Content-Type: application/json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Sat, 16 Apr 2016 12:37:59 GMT < Connection: close {noformat} The server produces the following exception: {noformat} java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException} at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361) ~[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1] at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] at org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] … {noformat} I was caught by surprise to see that as the two methods mentioned — [{{RepositoryEntityController.headCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L160] and [{{RepositoryEntityController. getCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L193] are considered ambiguous as they actually declare request mappings for different HTTP methods. {{getCollectionResource}} clearly maps to {{GET}}, not {{HEAD}}. On Spring 4.2 this works as expected as you can see by downgrading the example to Spring Boot 1.4.0.M1 (by tweaking the version number of the Boot parent in the root project's POM).

    Spring JIRA | 8 months ago | Oliver Gierke
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}
  6. 0

    @ExceptionHandler Unsupported argument

    Stack Overflow | 2 years ago | pedron4
    java.lang.IllegalStateException: Unsupported argument [javax.servlet.http.HttpServletResponse] for @ExceptionHandler method: public void ...portlet.BaseController.handleExpiredSession(javax.servlet.http.HttpServletResponse)

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]: {public com.ca.bean.ErrorWrapper com.ca.exceptionHandler.RestResponseEntityExceptionHandler.handleMethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException), public final org.springframework.http.ResponseEntity org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest)}

      at org.springframework.web.method.annotation.ExceptionHandlerMethodResolver.addExceptionMapping()
    2. Spring
      ExceptionHandlerMethodResolver.<init>
      1. org.springframework.web.method.annotation.ExceptionHandlerMethodResolver.addExceptionMapping(ExceptionHandlerMethodResolver.java:109)[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2. org.springframework.web.method.annotation.ExceptionHandlerMethodResolver.<init>(ExceptionHandlerMethodResolver.java:76)[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2 frames
    3. Spring MVC
      ExceptionHandlerExceptionResolver.afterPropertiesSet
      1. org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.initExceptionHandlerAdviceCache(ExceptionHandlerExceptionResolver.java:265)[spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2. org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.afterPropertiesSet(ExceptionHandlerExceptionResolver.java:241)[spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2 frames
    4. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      5. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      6. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      7. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      8. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      9. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      9 frames
    5. Spring Context
      AbstractApplicationContext.refresh
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2 frames
    6. Spring
      ContextLoaderListener.contextInitialized
      1. org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      2. org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      3. org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE]
      3 frames
    7. Glassfish Core
      ContainerBase$StartChild.call
      1. org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)[catalina.jar:7.0.70]
      2. org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)[catalina.jar:7.0.70]
      3. org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)[catalina.jar:7.0.70]
      4. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)[catalina.jar:7.0.70]
      5. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)[catalina.jar:7.0.70]
      5 frames
    8. Java RT
      Thread.run
      1. java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0_92]
      2. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_92]
      3. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[na:1.8.0_92]
      4. java.lang.Thread.run(Thread.java:745)[na:1.8.0_92]
      4 frames