어드바이스는 각 포인트컷에 삽입되어 동작할 횡단관심에 해당되는 공통기능
동작시점
<aop:before> : 비즈니스 메소드 실행 전 무조건 실행
<aop:after> : 비즈니스 메소드 실행 후 무조건 실행 ( try-catch-finally )
<aop:around> : 비즈니스 메소드 실행 전후에 실행
<aop:after-returning> : 비즈니스 메소드 성공적인 실행(예외없이) 후에 동작
<aop:after-throwing> : 비즈니스 메소드 실행 중에 예외 발생시에 동작(try-catch에서 catch에서 발생)
<context:component-scan base-package="com.spring.aopex2"/>
<bean id = "before" class = "com.spring.aopex2.BeforeAdvice" /> <!-- before 객체가 만들어짐 -->
<aop:config>
<aop:pointcut expression="execution(* com.spring.aopex2..*Impl.insertBoardDo(..))" id="insertDoPointcut"/>
<aop:aspect ref = "before">
<aop:before method="beforeLogDo" pointcut-ref="insertDoPointcut"/>
</aop:aspect>
</aop:config>
<bean id = "after" class = "com.spring.aopex2.AfterAdvice" />
<aop:config>
<aop:pointcut expression = "execution(* com.spring.aopex2..*Impl.insert*(..))" id = "insertPointcut"/>
<aop:aspect ref = "after">
<aop:after method = "afterAdvice" pointcut-ref = "insertPointcut"/>
</aop:aspect>
</aop:config>
<bean id = "around" class = "com.spring.aopex2.AroundAdvice" />
<aop:config>
<aop:pointcut expression = "execution(* com.spring.aopex2..*Impl.insert*(..))" id = "insertPointcut"/>
<aop:pointcut expression="execution(* com.spring.aopex2..*Impl.insertBoardReturn(..))" id="insertReturnPointcut"/>
<aop:aspect ref = "around">
<aop:around method = "aroundAdvice" pointcut-ref="insertPointcut" />
</aop:aspect>
<aop:aspect ref = "around">
<aop:around method = "aroundAdviceDo" pointcut-ref="insertReturnPointcut" />
</aop:aspect>
</aop:config>
횡단관심에 해당하는 어드바이스 메소드 구현시에,
포인트컷에 해당되는 메소드의 정보(메소드 이름, 매개변수의 값등)가 필요할 수 있음
디버깅, 로그, 예외처리 등의 포인트 컷 메소드의 정보가 필요함
❗️ Main로직의 인자들이 잘 들어오고 싶은지 확인, 값이 잘 들어오는지 확인하고 싶어서 사용
<bean id = "afterReturning" class = "com.spring.aopex2.AfterReturningAdvice" />
<aop:config>
<aop:pointcut expression = "execution(* com.spring.aopex2..*Impl.insert*(..))" id = "insertPointcut"/>
<aop:pointcut expression="execution(* com.spring.aopex2..*Impl.update*(..))" id="updatePointcut"/>
<aop:pointcut expression="execution(* com.spring.aopex2..*Impl.insertBoardReturn(..))" id="insertReturnPointcut"/>
<!-- <aop:aspect ref = "afterReturning">
<aop:before method="afterReturningAdviceLog" pointcut-ref = "insertPointcut" />
<aop:after-returning method="afterReturningAdviceLog" pointcut-ref="updatePointcut"/>
</aop:aspect> -->
<aop:aspect ref = "afterReturning">
<aop:after-returning method = "afterReturningAdviceLogDo"
pointcut-ref="insertReturnPointcut"
returning="returnObj" />
</aop:aspect>
</aop:config>
<bean id = "afterThrowing" class = "com.spring.aopex2.AfterThrowingAdvice" />
<aop:config>
<aop:pointcut expression = "execution(* com.spring.aopex2..*Impl.insert*(..))" id = "insertPointcut"/>
<aop:pointcut expression="execution(* com.spring.aopex2..*Impl.insertBoardExcept(..))" id="insertExceptPointcut"/>
<!-- <aop:aspect ref="afterThrowing">
<aop:after-throwing method="afterThrowingAdviceLog" pointcut-ref="insertPointcut"/>
</aop:aspect> -->
<aop:aspect ref = "afterThrowing">
<aop:after-throwing method = "afterThrowingLogExcept"
pointcut-ref="insertExceptPointcut"
throwing="exceptObj" />
</aop:aspect>
</aop:config>