Posts

Showing posts from December, 2014

Explore Spring 4 Features - Part 3

In this Post I will Capture the following features: 1) Controller Advice with Custom Annotation 2) Capturing Attributes in ModelAndView with the help of ModelMap while forwarding request from One Controller to another.(Not a Spring 4 feature) Part1: By Using @ControllerAdvice annotation we can apply an Advice across all the controllers in an application. Here our objective is to apply an advice not to all the controllers in an Application Context, but to them annotated with a custom annotation @NoControllerAdviseAnnotated in this case. The advice that would be applied out here is @ExceptionHandler(Exception.class) for Exception class. Our Code for ControllerAdvice is as follows: @ControllerAdvice(annotations=NoControllerAdviseAnnotated.class) public class CustomControllerAdvice { @ExceptionHandler(Exception.class) public ModelAndView handleException(Exception exception,WebRequest request) { ModelAndView mv = new