java - @ControllerAdvice Not Firing -


I'm working on a Spring MVC / Webflow application (version 3.2) and I'm working exception handling where I get the output Can I do a custom exception message for a logfile and error.jsp? The problem I am facing is that the exception handler is not removed. I have created the following class and annotated it as " @ControllerAdvice " and put it in the same package as my controller, which is throwing an exception:

  @ ControllerAdvice public class MyCustomExceptionController {@ExceptionHandler (MyCustomException.class) Public ModelAndView HandleMei Expansion (Before MyCustomException) {ModelAndView Model AndView = New ModelAndView (); ModelAndView.setViewName ("/ error / error"); Model ANDView.addObject ("errorId", ex.getErrorId ()); Model ANDView.addObject ("Message", ex.getErrorMessage ()); Return Model Endview; }}  

and added the following to the mvc-config file:

  & lt; Mvc: annotation-driven / & gt;  

And my app-config file contains the following:

  & lt; Reference: component-scan base-package = "My Controllers and MyCustomExceptionController Packaged" & gt; & Lt; Reference: Include-filter type = "annotation" expression = "org.springframework.web.bind.annotation.ControllerAdvice" /> & Lt; / Reference: Component Scan & gt;  

Any idea why this is not working?

& lt; Mvc: annotation-driven / & gt; Exception Handler Expression Resolver This section contains an initExceptionHandlerAdviceCache () method, which scans the beans in context to find them, Whose category types are annotated with @ControllerAdvice .

This is by calling first. Internally, this method uses this method.

does not consider any hierarchy that this factory can participate

its The meaning is what it means. When you declare ContextLoaderListener in your deployment descriptor, this is what we call the root or app ApplicationContext and it provides it in ServletContext . When you declare a DispatcherServlet , it creates its own servlet ApplicationContext and uses ApplicationContext ContextLoaderListener as parent in that context> AllCalcontext attributes hierarchy looks like this

  root ApplicationContext // ContextLoaderListener Loaded by Every  ApplicationContext  has access to beans in parent references, but is not around other methods.  

The above method selects not to use beans in the original contexts and therefore currently can be reached by ApplicationContext ( BeanFactory actually) beans.

As such, if your

  & lt; Reference: component-scan ... />  

is declared in the root ApplicationContext because I have to name it with the name app-config , but

< Previous> & lt; Mvc: annotation-driven / & gt;

is declared in the servlet ApplicationContext , again with mvc-config , then ExceptionHandlerExceptionResolver Seeing @ControllerAdvice will not get any for the beans This servlet is looking for beans in the context, but they are not there, they are in the root context.


Comments