Exception handling in jsr286 portlet

I am trying to handle an exception in a spring portlet-based user interface application ,

I used spring globalexception handlingwith @ControllerAdvice.

It works fine in a servlet application, but does not work in a portlet application. I noticed that the spring container did not process @ControllerAdviceon the portlet. I tried searching the Internet for the same issue, but no luck.

Is there any other way to handle exceptions in portlet applications?

Thanks in advance.

+4
source share
2 answers

Portlet Spring , . , DispatcherPortlet AnnotationMethodHandlerExceptionResolver, ExceptionHandlerExceptionResolver.

portlet.xml, DispatcherPortlet, org.springframework.web.portlet.HandlerExceptionResolver, , org.springframework.web.servlet.HandlerExceptionResolver ( ExceptionHandlerExceptionResolver ).

+3

, , . PortletControllerAdvice ( , , @ControllerAdvice), .

public abstract class PortletControllerAdvice {

    @ExceptionHandler({ NotAuthorizedException.class, WebApplicationException.class })
    public ModelAndView handleRESTException(WebApplicationException ex, ResourceResponse response) {
        // Do stuff
    }
}

:

@Controller
public class ViewController extends PortletControllerAdvice {

}

, , , , , , , .

0

Source: https://habr.com/ru/post/1523866/


All Articles