Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 5-21.Example of Ordered Exception Resolver


<bean id="anotherExceptionMapping"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">





Pattern Matching Rules


The rules for pattern matching of the exception names might not be obvious, so we cover
them here. There are two rules to be aware of.


Rule Number One
The first rule to be aware of is that the shorter the pattern string, the higher priority it will
receive. For example, the mapping Excepwill match any exception whose class name contains
that substring (in other words, nearly every exception). Even if you have another mapping
with the exact class name, the shorter Excep mapping will resolve first. Listings 5-22 through
5-24 illustrate this.
Listing 5-22 contains the two exception classes we’ll use for this example. It is a simple
class hierarchy, with ExceptionChildsubclassing ExceptionParent.


Listing 5-22.Example Exception Classes


public class ExceptionParent extends Exception { }
public class ExceptionChild extends ExceptionParent{ }


Listing 5-23 illustrates an exception resolver with two mappings. The first is a very general
mapping, handling any exception whose name includes the substring Excep. The second map-
ping is an explicit mapping for an exception whose names includes the fuller ExceptionChild.


Listing 5-23.Exception Mapping Example


<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">



class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">


exceptionPage
moreSpecificPage




CHAPTER 5 ■THE PROCESSING PIPELINE 97
Free download pdf