[ 이전 글 ]
After Returning • Throwing Advice
After Returning • Throwing Advice
[ 이전 글 ] BeforeAdvice BeforeAdvice [ 이전 글 ] Around Advice ( ver. Spring ) Around Advice ( ver. Spring ) [ 이전 글 ]Aspect Oriented Programming ( 2 ) Aspect Oriented Programming ( 2 ) [ 이전 글 ] Aspect Oriented Programming ( 1 ) Aspect Or
cloakinghost.tistory.com
Weaving : 주업무와 보조업무를 엮는행위 ( 뜨개질의 의미를 가진 단어임 )
JoinPoint : Proxy의 타켓이 가진 메소드 중 실행 할 수 있는 메소드
Pointcuts : Proxy에서 실행할 메소드, 원하는 메소드만 실행
Advisor : Advice와 Pointcut과 연결하는 클래스
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<!-- main -->
<bean id="target" class="spring.aop.entity.ScoreExam" p:kor="1" p:eng="1" p:math="1" p:com="1"/>
<!-- Advice -->
<bean id="logAroundAdvice" class="spring.aop.advice.LogAroundAdvice"/>
<bean id="logBeforeAdvice" class="spring.aop.advice.LogBeforeAdvice"/>
<bean id="logAfterReturningAdvice" class="spring.aop.advice.LogAfterReturningAdvice"/>
<bean id="logAfterThrowingAdvice" class="spring.aop.advice.LogAfterThrowingAdvice"/>
<!-- Pointcut -->
<bean id="classicPointCut" class="org.springframework.aop.support.NameMatchMethodPointcut">
<property name="mappedName" value="total"/>
</bean>
<!-- connect advice and pointcut -->
<bean id="classicBeforeAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice" ref="logBeforeAdvice"/>
<property name="pointcut" ref="classicPointCut"/>
</bean>
<bean id="classicAroundAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice" ref="logAroundAdvice"/>
<property name="pointcut" ref="classicPointCut"/>
</bean>
<!-- Proxy -->
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="target"/>
<property name="interceptorNames">
<list>
<value>classicAroundAdvisor</value>
<value>classicBeforeAdvisor</value>
<value>logAfterReturningAdvice</value>
<value>logAfterThrowingAdvice</value>
</list>
</property>
</bean>
</beans>
Advisor를 하나씩 추가하면서 main()을 실행해보면서 차이점을 느껴보자
Pointcut에서 total() 메소드만 실행하기 때문에 avg() 메소드 실행때와 다른 결과가 출력된다
Pointcut과 Advisor의 property는 각 객체별로 가지고 있는 setter이다 즉, 고정이다
가장 클래식한 방법으로 XML의 길이가 많이 길어진다
다음글에서 더 편하게 변형해보자
728x90
'Spring' 카테고리의 다른 글
Spring Legacy 기본세팅 ( 1 ) (0) | 2023.08.08 |
---|---|
Advisor ( 2 ) (0) | 2023.08.08 |
After Returning • Throwing Advice (0) | 2023.08.07 |
BeforeAdvice (0) | 2023.08.07 |
Around Advice ( ver. Spring ) (0) | 2023.08.07 |