0
0
Spring Bootframework~10 mins

AOP for performance monitoring in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an aspect class for performance monitoring.

Spring Boot
import org.aspectj.lang.annotation.[1];

@Aspect
public class PerformanceAspect {

}
Drag options to blanks, or click blank then click option'
AAspect
BComponent
CService
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Aspect
Forgetting to import the annotation
Confusing @Service with @Aspect
2fill in blank
medium

Complete the code to define a pointcut expression that matches all methods in the service package.

Spring Boot
@Pointcut("execution(* com.example.service..*[1]*(..))")
public void serviceMethods() {}
Drag options to blanks, or click blank then click option'
A+
B.
C*
D#
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '*' for method names
Using '+' which is for class inheritance
Using '#' which is not valid here
3fill in blank
hard

Fix the error in the advice method to correctly measure execution time.

Spring Boot
@Around("serviceMethods()")
public Object measureTime(ProceedingJoinPoint joinPoint) throws Throwable {
    long start = System.currentTimeMillis();
    Object result = joinPoint.[1]();
    long end = System.currentTimeMillis();
    System.out.println("Execution time: " + (end - start) + " ms");
    return result;
}
Drag options to blanks, or click blank then click option'
Aexecute
Bproceed
Crun
Dcall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' which does not exist
Using 'run' which is unrelated
Using 'call' which is invalid here
4fill in blank
hard

Fill both blanks to log the method name and execution time inside the advice.

Spring Boot
String methodName = joinPoint.getSignature().[1]();
System.out.println("Method " + methodName + " took " + [2] + " ms");
Drag options to blanks, or click blank then click option'
AgetName
Bend - start
CgetClassName
Dstart - end
Attempts:
3 left
💡 Hint
Common Mistakes
Using getClassName instead of getName
Subtracting times in wrong order
Printing variables before they are defined
5fill in blank
hard

Fill all three blanks to create a complete around advice that measures and logs execution time for service methods.

Spring Boot
@Around("[1]")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
    long [2] = System.currentTimeMillis();
    Object result = joinPoint.proceed();
    long [3] = System.currentTimeMillis();
    System.out.println("Execution time: " + (end - start) + " ms");
    return result;
}
Drag options to blanks, or click blank then click option'
AserviceMethods()
Bstart
Cend
Dexecution(* com.example.repository..*(..))
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pointcut expression
Mixing up start and end variable names
Forgetting to call proceed()