Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class as an aspect using the correct annotation.
Spring Boot
@[1] public class LoggingAspect { // aspect code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Aspect
Forgetting the '@' symbol
Using unrelated annotations like @Service
✗ Incorrect
The @Aspect annotation marks a class as an aspect in Spring AOP.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' which matches package separator
Using '+' or '#' which are not valid here
✗ Incorrect
The '*' wildcard matches any method name in the pointcut expression.
3fill in blank
hardFix the error in the advice method declaration by completing the annotation.
Spring Boot
@[1]("serviceMethods()") public void logBefore() { System.out.println("Method is about to execute"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @After instead of @Before
Using @Around without proper method signature
✗ Incorrect
The @Before annotation runs advice before the matched method executes.
4fill in blank
hardFill both blanks to create an aspect class that logs before and after method execution.
Spring Boot
@Aspect public class LoggingAspect { @[1]("execution(* com.example..*(..))") public void logStart() { System.out.println("Start method"); } @[2]("execution(* com.example..*(..))") public void logEnd() { System.out.println("End method"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @AfterReturning instead of @After for the second advice
Mixing up the order of annotations
✗ Incorrect
Use @Before to run code before method execution and @After to run code after method execution.
5fill in blank
hardFill all three blanks to define an around advice that logs method execution time.
Spring Boot
@Aspect public class PerformanceAspect { @Around("[1]") public Object measureTime(ProceedingJoinPoint [2]) throws Throwable { long start = System.currentTimeMillis(); Object result = [3].proceed(); long end = System.currentTimeMillis(); System.out.println("Execution time: " + (end - start) + "ms"); return result; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pointcut expression
Mismatching parameter name and usage
Forgetting to call proceed()
✗ Incorrect
The pointcut expression matches all methods, the parameter is named joinPoint, and proceed() is called on it.