0
0
Spring Bootframework~20 mins

Cross-cutting concerns concept in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cross-cutting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Cross-cutting Concerns in Spring Boot
Which of the following best describes a cross-cutting concern in a Spring Boot application?
AA UI component that handles user input.
BA feature that affects multiple parts of the application, like logging or security, implemented separately from business logic.
CA database entity that stores user information.
DA specific business rule applied only in one service class.
Attempts:
2 left
💡 Hint
Think about features that are needed across many parts of the app, not just one place.
component_behavior
intermediate
2: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;
    }
}
AThe method runs twice because of the aspect.
BThe method is skipped and only the execution time is printed.
CThe method throws a runtime exception due to missing annotation.
DThe method runs normally and its execution time is printed to the console.
Attempts:
2 left
💡 Hint
The aspect wraps the method to measure time but does not prevent execution.
📝 Syntax
advanced
2: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?
A@Pointcut("execution(* com.example.service..*(..))")
B@Pointcut("execution(* com.example.service.*(..))")
C@Pointcut("execution(* com.example..service.*(..))")
D@Pointcut("execution(* com.example.service.*.*(..))")
Attempts:
2 left
💡 Hint
Use '..' to include subpackages in pointcut expressions.
🔧 Debug
advanced
2: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?
AThe aspect class is not annotated with @Component or not scanned by Spring.
BThe application is missing a database connection.
CThe method being called is private.
DThe method has no parameters.
Attempts:
2 left
💡 Hint
Spring needs to know about the aspect bean to apply it.
state_output
expert
3: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;
    }
}
ACompilation error due to missing annotations on Service class.
BTwo lines printed showing execution time for each process() call.
CNo output because the aspect is not applied to the service instance created with new.
DOne line printed showing execution time for the first call only.
Attempts:
2 left
💡 Hint
Spring AOP works only on Spring-managed beans, not on objects created with new.