[ 이전 글 ] Around Advice ( ver. Spring )
Around Advice ( ver. Spring )
[ 이전 글 ]Aspect Oriented Programming ( 2 ) Aspect Oriented Programming ( 2 ) [ 이전 글 ] Aspect Oriented Programming ( 1 ) Aspect Oriented Programming ( 1 ) Aspect Oriented Programming 관점 지향 프로그래밍 ( 방법론 ) OOP 사용자가
cloakinghost.tistory.com
package spring.aop.advice;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class LogBeforeAdvice implements MethodBeforeAdvice {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
// 현재 호출되고 있는 함수의 이름
System.out.println(method.getName());
// 현재 함수의 파라미터
for(Object e : args) {
System.out.println(e);
}
// 객체의 정보
System.out.println(target);
System.out.println("앞에서 실행 될 로직");
}
}
XML
<?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">
<bean id="target" class="spring.aop.entity.ScoreExam" p:kor="1" p:eng="1" p:math="1" p:com="1"/>
<bean id="logAroundAdvice" class="spring.aop.advice.LogAroundAdvice"/>
<bean id="logBeforeAdvice" class="spring.aop.advice.LogBeforeAdvice"/>
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="target"/>
<property name="interceptorNames">
<list>
<value>logAroundAdvice</value>
<value>logBeforeAdvice</value>
</list>
</property>
</bean>
</beans>728x90
'Spring' 카테고리의 다른 글
| Advisor ( 1 ) (0) | 2023.08.08 |
|---|---|
| After Returning • Throwing Advice (0) | 2023.08.07 |
| Around Advice ( ver. Spring ) (0) | 2023.08.07 |
| Around Advice ( ver. Java Project ) (0) | 2023.08.07 |
| Aspect Oriented Programming (0) | 2023.08.07 |