public class ExceptionMappingAdvice extends Object implements ThrowsAdvice, Ordered
Use this Advice to map one exception to another for use when other advice eats your runtime exceptions outside of your code. This happens in Transactions when commit is not called until outside of your DAO layer.
Set the property "exceptionMapping" as a map that maps an exception class to your own exception class
Remember that aspect order is important and that this bean will always be order "500"
Example:<tx:annotation-driven transaction-manager="JtaTxManager" order="1000"/> lt;bean id="mapExceptionAdvisor" class="org.myfoo.ExceptionMappingAdvice"> <property name="exceptionMapping"> <map> <entry key="javax.persistence.EntityExistsException" value="org.myfoo.exceptions.AlreadyExistsException" /> </map> </property> lt;/bean> lt;aop:config> <aop:aspect id="dataAccessToBusinessException" ref="mapExceptionAdvisor"> <aop:after-throwing pointcut="execution(* org.myfoo.service.*.*(..))" method="afterThrowing" throwing="ex" /> </aop:aspect> lt;/aop:config>
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ExceptionMappingAdvice() |
Modifier and Type | Method and Description |
---|---|
void |
afterThrowing(Exception ex)
This method will use the real exception thrown and look up the exception
that should be thrown
|
Class<? extends Exception> |
getDefaultException() |
Map<Class<? extends Exception>,Class<? extends Exception>> |
getExceptionMapping() |
int |
getOrder() |
void |
setDefaultException(Class<? extends Exception> defaultException) |
void |
setExceptionMapping(Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping) |
void |
setOrder(int order) |
public ExceptionMappingAdvice()
public void afterThrowing(Exception ex) throws Exception
ex
- Exception
public void setOrder(int order)
order
- the order to setpublic Map<Class<? extends Exception>,Class<? extends Exception>> getExceptionMapping()
public void setExceptionMapping(Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping)
exceptionMapping
- the exceptionMapping to setpublic Class<? extends Exception> getDefaultException()
public void setDefaultException(Class<? extends Exception> defaultException)
defaultException
- the defaultException to setCopyright © 2004-2013 The Kuali Foundation. All Rights Reserved.