과제 검토 및 제출, 복습
웹 애플리케이션이나 프레임워크에서 요청(request)이나 응답(response)이 컨트롤러에 도달하거나 클라이언트에게 반환되기 전에 가로채서 처리할 수 있는 기능
@Component
public class Interceptor implements HandlerInterceptor {
}
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
private final HandlerInterceptor handlerInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(handlerInterceptor).addPathPatterns("경로");
}
}
이렇게 WebConfig에 등록하면 됨
AOP는 관심사를 분리해서, 공통 기능(로깅, 트랜잭션, 인증 등)을 핵심 로직과 분리하는 기법
@Aspect // aop를 만들 때 어노테이션 필수
@Component // aop 사용시 빈 등록도 필수
@Slf4j
public class Aspect {
@Around()
public Object 메서드명(ProceedingJoinPoint joinPoint) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes())
.getRequest();
// 실행 전 로직
Object result = joinPoint.proceed(); // 해당하는 클래스의 메소드 실행
// 실행 후 로직
return result;
}
implementation 'org.springframework.boot:spring-boot-starter-aop'
어떤 메서드에 Advice를 적용할지 정하는 조건(AOP 적용 대상 선정 기준)

exexution표현식 구조
execution([접근제어자] 리턴타입 패키지명.클래스명.메서드명(파라미터))
커스텀 어노테이션 만드는 법
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface 어노테이션명 {
}
ex)
@Around("@annotation(어노테이션이 있는 경로)")
@Around("execution( )")
일단 이 정도만 작성하고 더 자세한 내용은 좀 더 배우면 적겠습니다.
컨디션이 안 좋아서 집중을 잘 못하다가 그나마 저녁쯤이 되니까 좀 괜찮아져서 다시 공부를 재개했다.. 주말엔 다 나을 줄 알았는데 생각보다 오래가는 것 같다. 😭 그래도 오늘 집중이 다시 되는 걸 보니 희망이 보이네요👍