通知类:
public class ExceptionAdvisor implements ThrowsAdvice {// @AfterThrowing(pointcut = "execution(* com.ningpai..*.*(..))") public void afterThrowing(Method method, Object[] args, Object target, Exception ex) throws Throwable { // 在后台中输出错误异常异常信息,通过log4j输出。// Logger log = Logger.getLogger(target.getClass());// for (int i = 0; i < args.length; i++) {// log.error("arg[" + i + "]: " + args[i]);// }// log.error("Exception class: " + ex.getClass().getName());// log.error("ex.getMessage():" + ex.getMessage());// log.error(ex); ex.printStackTrace(); }}
ApplicationContext.xml的相关配置:
com.project.*
exceptionInterceptor