0
0
Spring Bootframework~20 mins

AOP for logging in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
AOP Logging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding AOP Pointcut Expressions

Which pointcut expression correctly matches all methods in classes within the package com.example.service and its subpackages?

Awithin(com.example.service.*)
Bexecution(* com.example.service.*(..))
Cexecution(* com.example.service..*(..))
Dexecution(* com.example.service..*.*(..))
Attempts:
2 left
💡 Hint

Remember that .. matches subpackages and any number of arguments.

💻 Command Output
intermediate
2:00remaining
Output of Logging Aspect Around Advice

Given the following Spring AOP around advice, what will be printed when the method processOrder() is called?

Spring Boot
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("Start: " + joinPoint.getSignature().getName());
    Object result = joinPoint.proceed();
    System.out.println("End: " + joinPoint.getSignature().getName());
    return result;
}
AStart: processOrder\nEnd: processOrder
BStart: processOrder
CEnd: processOrder\nStart: processOrder
DEnd: processOrder
Attempts:
2 left
💡 Hint

Think about the order of statements before and after proceed().

Configuration
advanced
2:00remaining
Correct Aspect Configuration for Logging

Which of the following Spring configuration snippets correctly enables AspectJ auto-proxying and declares a logging aspect bean?

A@Configuration\n@ComponentScan(basePackages = "com.example")\npublic class AppConfig {\n}
B@Configuration\n@EnableAspectJAutoProxy\npublic class AppConfig {\n @Bean\n public LoggingAspect loggingAspect() {\n return new LoggingAspect();\n }\n}
C@EnableAspectJAutoProxy\n@Component\npublic class LoggingAspect {}
D@Configuration\n@EnableTransactionManagement\npublic class AppConfig {\n @Bean\n public LoggingAspect loggingAspect() {\n return new LoggingAspect();\n }\n}
Attempts:
2 left
💡 Hint

Enabling AspectJ auto-proxying is required for aspects to work.

Troubleshoot
advanced
2:00remaining
Diagnosing Missing Logs from Aspect

A developer created a logging aspect with @Around advice but no logs appear when methods run. What is the most likely cause?

AThe aspect class is not annotated with <code>@Aspect</code>
BThe methods being called are private
CThe logging statements use <code>System.out.println</code> instead of a logger
DThe application is missing <code>spring-boot-starter-web</code> dependency
Attempts:
2 left
💡 Hint

Check if the aspect is recognized by Spring AOP.

Best Practice
expert
2:00remaining
Choosing the Best Advice Type for Logging Execution Time

Which advice type is best suited to measure and log the execution time of a method in Spring AOP?

A@Before advice, because it runs before the method starts
B@AfterReturning advice, because it runs after method returns successfully
C@AfterThrowing advice, because it runs if the method throws an exception
D@Around advice, because it can run code before and after method execution
Attempts:
2 left
💡 Hint

Think about needing to capture time before and after the method runs.