Loading

Quipoin Menu

Learn • Practice • Grow

spring / Joinpoints in AOP
interview

Q1. What is a joinpoint in AOP?
A joinpoint is a point during the execution of a program, such as method invocation, constructor call, or field access. In Spring AOP, only method execution joinpoints are supported. Advice is associated with a pointcut expression that matches specific joinpoints.

Q2. How do you access information about the joinpoint in advice?
Advice methods can declare a parameter of type JoinPoint (or ProceedingJoinPoint for around). JoinPoint provides methods like getSignature(), getArgs(), getTarget(), etc., to access details of the intercepted method. Example:
@Before("execution(* *.*(..))") public void before(JoinPoint jp) { System.out.println(jp.getSignature().getName()); }

Q3. What is the difference between joinpoint and pointcut?
A joinpoint is a specific point in the program (e.g., a method call), while a pointcut is an expression that selects one or more joinpoints. Pointcuts define where advice should be applied. For example, a pointcut might select all methods in a service package.

Q4. Can you use joinpoints for field access in Spring AOP?
No, Spring AOP only supports method execution joinpoints. If you need field interception, you would need to use AspectJ with compile-time or load-time weaving.

Q5. What is the JoinPoint API in Spring?
The JoinPoint interface provides reflective access to the state of the joinpoint. For around advice, ProceedingJoinPoint extends JoinPoint and adds the proceed() method to execute the target method. These are part of the org.aspectj.lang package.