@Aspect 어노테이션을 이용한 AOP
1. @Aspect 어노테이션을 이용하여 Aspect 클래스에 직접 Advice 및 Point등을 직접 설정
2. 설정파일에 <aop:aspectj-autoproxy/> 를 추가 해야함
3. Aspect class를 <bean>으로 등록
4. 어노테이션(Annotation)
- @Aspect : Aspect 클래스 선언
- @Before("pointcut")
- @AfterReturning(pointcut="", returning="")
- @AfterThrowing(pointcut="",throwing="")
- @After("pointcut")
- @Around("pointcut")
5. Around를 제외한 나머지 메소드들은 첫 argument로 JoinPoint를 가질 수 있다.
6. Around 메소드는 argument로 ProceedingJoinPoint를 가질 수 있다.
* 결과
------------정상처리----------------
AdviceClass.before.beforeLogger()---------------------
AdviceClass.aroundLogger() 실행----------------
Business메소드가 실행되었습니다.
AdviceClass.afterReturnLogger()--------------
null
AdviceClass.afterLogger()----------------------
------------에러내기----------------
AdviceClass.before.beforeLogger()---------------------
AdviceClass.aroundLogger() 실행----------------
AdviceClass.afterThrowLogger()----------------------
i가 0보다 작다
Exception in thread "main" AdviceClass.afterLogger()----------------------
java.lang.RuntimeException: i가 0보다 작다
at aop.core.CoreClass.businessMethod(CoreClass.java:6)
at aop.core.CoreClass$$FastClassByCGLIB$$359776d6.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:692)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at aop.common.AdviceClass.aroundLogger(AdviceClass.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625)
at aop.core.CoreClass$$EnhancerByCGLIB$$cebdb4e6.businessMethod(<generated>)
at TestMain.main(TestMain.java:14)
'프로그래밍 > Spring AOP' 카테고리의 다른 글
Spring AOP around- spring_03_stu[실습] (0) | 2012.06.26 |
---|---|
AOP around실습 - spring_aop_03_around (0) | 2012.06.25 |
AOP[실습] - spring_aop_shop_stu (0) | 2012.06.25 |
POJO 기반 AOP 구현 - Advice 클래스 작성(After Returning, After Throwing, After)- spring_aop_02_after[실습] (0) | 2012.06.25 |
Spring_aop[실습] (0) | 2012.06.22 |