运行@Before@After@Around都是好的,但是@AfterThrowing不执行。下面是代码:
*************************************************************************************************
@Aspect
public class PointcutsDefinition {
@AfterThrowing(value=”execution(* com.asrkuya.service..*.*(..))”,argNames=”exception”,throwing=”exception”)
public void afterThrowingAdvice(Exception exception){
System.out.println(“hello”);
System.out.println(“=============after throwing advice exception:”+exception);
}
}
******************************************************************************************************
public class TestService {
public void justTest(String outString){
System.out.println(outString);
throw new RuntimeException();
}
public static void main(String [] args){
ApplicationContext ctx=new FileSystemXmlApplicationContext(“config/ApplicationContext.xml”);
TestService ts=(TestService) ctx.getBean(“test”);
ts.justTest(” hello world!”);
System.exit(0);
}
}
************************************************************************************************************
<aop:aspectj-autoproxy/>
<!–
<bean class=”com.sarkuya.aop.advice.SampleAdvice”></bean>
–>
<bean class=”com.sarkuya.aop.pointcut.PointcutsDefinition”></bean>
<bean id=”test” class=”com.sarkuya.service.TestService”></bean>
****************************************************************************************************************
运行结果:
hello world!
Exception in thread “main” java.lang.RuntimeException
at com.sarkuya.service.TestService.justTest(TestService.java:9)
at com.sarkuya.service.TestService.main(TestService.java:14)