当前位置: 代码迷 >> J2EE >> aop @AfterThrowing不执行,求大神见教
  详细解决方案

aop @AfterThrowing不执行,求大神见教

热度:1322   发布时间:2016-04-17 23:38:39.0
aop @AfterThrowing不执行,求大神指教
运行@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)
------解决思路----------------------
execution(* com.sarkuya.service..*.*(..))


你写错包名了,

"execution(* com.asrkuya.service..*.*(..))