@AspectJ 사용시 어노테이션 설정 까먹지말것!

박상준·2022년 10월 12일
0

실무

목록 보기
4/8
@Aspect
@EnableAspectJAutoProxy
@Component
@Slf4j
public class LogAop {
    @Pointcut("execution(* egovframework.com.ecms.archive.web.*Controller.*(..))")
    private void logCut1() {
    
    }
    
    @Pointcut("execution(* egovframework.com.ecms.archive.customtype.post.web.*Controller.*(..))")
    private void logCut2() {
    
    }
    
    @Before("logCut1() || logCut2()")
    public Object around(JoinPoint joinPoint) throws Throwable {
        //메서드 시작점
        log.info("joinPoint : "+ joinPoint);
        System.out.println("헬로");
    
        return null;
    }
    
}

@EnableAspectJAutoProxy 설정을 해 줘야한다.!!!! 잊지말것
Spring boot 의 경우 해당 자동프록시 설정을 최상단 클래스에
Spring legacy의 경우 해당 설정을 aspectJ 클래스에 설정해줘야한다.

profile
이전 블로그 : https://oth3410.tistory.com/

0개의 댓글