Challenge - 5 Problems
Cross-cutting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Cross-cutting Concerns in Spring Boot
Which of the following best describes a cross-cutting concern in a Spring Boot application?
Attempts:
2 left
💡 Hint
Think about features that are needed across many parts of the app, not just one place.
✗ Incorrect
Cross-cutting concerns are aspects like logging, security, or transaction management that affect many parts of an application. Spring Boot uses AOP to separate these from core business logic.
❓ component_behavior
intermediate2:00remaining
Behavior of Aspect in Spring Boot
Given a Spring Boot aspect that logs method execution time, what will happen when a method annotated with @LogExecutionTime is called?
Spring Boot
@Aspect @Component public class LoggingAspect { @Around("@annotation(com.example.LogExecutionTime)") public Object logTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long executionTime = System.currentTimeMillis() - start; System.out.println(joinPoint.getSignature() + " executed in " + executionTime + "ms"); return proceed; } }
Attempts:
2 left
💡 Hint
The aspect wraps the method to measure time but does not prevent execution.
✗ Incorrect
The @Around advice runs code before and after the method. It calls proceed() to run the method and then logs the time.
📝 Syntax
advanced2:00remaining
Correct Syntax for Defining a Pointcut
Which option correctly defines a pointcut that matches all methods in the package com.example.service and its subpackages?
Attempts:
2 left
💡 Hint
Use '..' to include subpackages in pointcut expressions.
✗ Incorrect
The '..' in the expression means any subpackage depth. Option A matches all methods in com.example.service and its subpackages.
🔧 Debug
advanced2:00remaining
Identifying the Cause of Aspect Not Triggering
A developer created an aspect to log method calls but notices it never runs. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
Spring needs to know about the aspect bean to apply it.
✗ Incorrect
For Spring AOP to work, the aspect must be a Spring bean, typically annotated with @Component and scanned by Spring. Otherwise, it won't be applied.
❓ state_output
expert3:00remaining
Output of Logging Aspect with Multiple Method Calls
Given the following Spring Boot aspect and service, what will be printed to the console when main() calls service.process() twice?
Spring Boot
public class Service { @LogExecutionTime public void process() throws InterruptedException { Thread.sleep(100); } } public class Main { public static void main(String[] args) throws InterruptedException { Service service = new Service(); service.process(); service.process(); } } @Aspect @Component public class LoggingAspect { @Around("@annotation(com.example.LogExecutionTime)") public Object logTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long time = System.currentTimeMillis() - start; System.out.println(joinPoint.getSignature() + " executed in " + time + "ms"); return proceed; } }
Attempts:
2 left
💡 Hint
Spring AOP works only on Spring-managed beans, not on objects created with new.
✗ Incorrect
The service instance is created manually with new, so Spring does not manage it and the aspect is not applied. No logging output appears.