프로그래밍 공부/Spring
[Spring] BeforeAdvice 구현하기
valid_ming
2021. 5. 5. 14:35
뉴렉처 강사님의 동영상 강의를 정리한 글입니다.
간단하게 MethodBeforeAdvice를 구현한 클래스를 사용하여 BeforeAdvice를 구현할 수 있다.
LogBeforeAdvice.java
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 {
// TODO Auto-generated method stub
System.out.println("앞에서 실행될 로직");
}
}
before 메서드의 method 인자를 이용하여 현재 호출되고 있는 함수의 이름 또는 그 함수가 가지는 파라미터를 정보를 얻을 수 있다. target 인자를 이용하여 target class 객체를 이용할 수도 있다.
