---
title: "Spring ThrowsAdvice使用例子"
author: "javapub"
date: "2011-02-10T19:01:37Z"
tags: ["AOP", "Java", "Spring"]
categories: ["企业架构"]
slug: "spring-throwsadvice"
draft: false
lastmod: "2011-02-10T19:01:37Z"
id: 903086
url: "https://javapub.iteye.com/blog/903086"
---

ThrowsAdvice用于拦截异常 \[code="java"] import java.lang.reflect.Method; import org.springframework.aop.ThrowsAdvice; public class DaoThrowsAdvice implements ThrowsAdvice { public void afterThrowing(Method m, Object args, Object target, Throwable subclass) { System.out.println("\[DaoThrowsAdvice]: An exception occur: " + subclass.getClass().getSimpleName()); System.exit(0); } } \[/code] 配置文件 \[code="java"] beforeDaoAdvice afterDaoAdvice throwsDaoAdvice aroundAdvice \[/code] 完整程序代码请参考附件。