Spring Aop Interview Qna - Chatgpt
Spring Aop Interview Qna - Chatgpt
Examples)
Q8. What is the difference between JDK Dynamic Proxy and CGLIB?
JDK Proxy: Requires interfaces
CGLIB Proxy: Works on concrete classes via subclassing
// JDK Proxy requires interface
public interface MyService {
void perform();
}
@Before("userServiceMethods()")
public void beforeUserService() {
System.out.println("Intercepted user service method");
}
@Around("@annotation(com.example.TrackTime)")
public Object trackTime(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
Object result = pjp.proceed();
System.out.println("Time taken: " + (System.currentTimeMillis() -
start));
return result;
}
@Aspect
@Order(2)
@Component
public class SecondAspect {}