Add @controlleradvice error Failed to invoke @ExceptionHandler method

Source: Internet
Author: User

First of all. Using Controlleradvice alone does not work correctly. Need to be used in conjunction with @enablewebmvc.

@ControllerAdvice

@EnableWebMvc

Pulbic class exceptioncontrolleradvice{

  @ExceptionHandler (notfoundexception. class)

  @ResponseBody

Public map<string,object> Notfoundexc (notfoundexception exc,httpservletrequest req) {

.......

}

}

Exception handling Error in startup.

Error message:

July 04, 2016 11:00:11 am org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver Doresolvehandlermethodexception

Severity: Failed to invoke @ExceptionHandler method:public java.util.map<java.lang.string, java.lang.object> Com.dooioo.modelException.ExceptionControllerAdvice.notFoundError (Com.dooioo.modelException.NotFoundException, Javax.servlet.http.httpservletrequest,javax.servlet.http.httpservletresponse)

Org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

At Org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters (abstractmessageconvertermethodprocessor.java:134)

At Org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters (abstractmessageconvertermethodprocessor.java:101)

At Org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue ( requestresponsebodymethodprocessor.java:185)

At Org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue ( HANDLERMETHODRETURNVALUEHANDLERCOMPOSITE.JAVA:71)

At Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( servletinvocablehandlermethod.java:126)

At Org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException (exceptionhandlerexceptionresolver.java:362)

At Org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException ( ABSTRACTHANDLERMETHODEXCEPTIONRESOLVER.JAVA:60)

At Org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException ( abstracthandlerexceptionresolver.java:138)

At Org.springframework.web.servlet.DispatcherServlet.processHandlerException (dispatcherservlet.java:1183)

At Org.springframework.web.servlet.DispatcherServlet.processDispatchResult (dispatcherservlet.java:1020)

At Org.springframework.web.servlet.DispatcherServlet.doDispatch (dispatcherservlet.java:971)

At Org.springframework.web.servlet.DispatcherServlet.doService (dispatcherservlet.java:893)

At Org.springframework.web.servlet.FrameworkServlet.processRequest (frameworkservlet.java:967)

At Org.springframework.web.servlet.FrameworkServlet.doGet (frameworkservlet.java:858)

At Javax.servlet.http.HttpServlet.service (httpservlet.java:622)

At Org.springframework.web.servlet.FrameworkServlet.service (frameworkservlet.java:843)

At Javax.servlet.http.HttpServlet.service (httpservlet.java:729)

At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:291)

At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)

At Org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal (hiddenhttpmethodfilter.java:77)

At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107)

At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:239)

At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)

At Org.apache.tomcat.websocket.server.WsFilter.doFilter (wsfilter.java:52)

At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:239)

At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)

At Org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (characterencodingfilter.java:85)

At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107)

At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:239)

At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)

At Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:217)

At Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:106)

At Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:502)

At Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:142)

At Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:79)

At Org.apache.catalina.valves.AbstractAccessLogValve.invoke (abstractaccesslogvalve.java:616)

At Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:88)

At Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:518)

At Org.apache.coyote.http11.AbstractHttp11Processor.process (abstracthttp11processor.java:1091)

At Org.apache.coyote.abstractprotocol$abstractconnectionhandler.process (abstractprotocol.java:673)

At Org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun (nioendpoint.java:1500)

At Org.apache.tomcat.util.net.nioendpoint$socketprocessor.run (nioendpoint.java:1456)

At Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1142)

At Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:617)

At Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (taskthread.java:61)

At Java.lang.Thread.run (thread.java:745)

The Messageconverter processor is already configured in the Xx-servlet.xml.

<Bean id= "dymessageconverter" class=" Com.dooioo.web.converter.DyMappingJacksonHttpMessageConverter "/>

<Bean class=" Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter ">

<!--spring binding processing function--

<property Name="Webbindinginitializer">

<Bean class="Com.dooioo.init.DefaultBindingInitializer"/>

</Property>

<property Name="messageconverters">

<list>

<Bean class="Org.springframework.http.converter.ByteArrayHttpMessageConverter" />

<ref Bean="Dymessageconverter"/>

</list>

</Property>

<property Name="Requiresession" value="false" />

<property name="order" value="0"/>

</Bean>

The internet turned over the data did not result.

The final discovery is related to the order in XML. <mvc:annotation-driven/>.

The Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter adapter must be declared in <MVC: Conversion of parameter types is not handled properly before Annotation-driven/>

To resolve this issue.

Add @controlleradvice error Failed to invoke @ExceptionHandler method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.