0
0
Spring Bootframework~10 mins

@Before advice 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 a method that runs before the target method using @Before advice.

Spring Boot
@Before("execution(* com.example.service.UserService.[1](..))")
public void beforeAdvice() {
    System.out.println("Before method execution");
}
Drag options to blanks, or click blank then click option'
AgetUser
BsetUser
CdeleteUser
DupdateUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in the service.
Forgetting to include parentheses (..).
2fill in blank
medium

Complete the code to import the correct package for @Before advice in Spring AOP.

Spring Boot
import org.aspectj.lang.annotation.[1];
Drag options to blanks, or click blank then click option'
ABefore
BAfter
CAround
DPointcut
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong annotation like @After or @Around.
Missing the import statement entirely.
3fill in blank
hard

Fix the error in the pointcut expression to correctly match all methods in the service package.

Spring Boot
@Before("execution(* com.example.service.[1].*(..))")
public void logBefore() {
    System.out.println("Method called");
}
Drag options to blanks, or click blank then click option'
A*
BUserService.*
CUserService..
DUserService
Attempts:
3 left
💡 Hint
Common Mistakes
Using double dots (..) incorrectly in the class name.
Adding extra wildcards in the class name.
4fill in blank
hard

Fill both blanks to create a @Before advice that runs before any method in any class inside the service package.

Spring Boot
@Before("execution(* com.example.service.[1].[2](..))")
public void beforeAnyMethod() {
    System.out.println("Before any service method");
}
Drag options to blanks, or click blank then click option'
A*
Bget*
Cset*
DUserService
Attempts:
3 left
💡 Hint
Common Mistakes
Using specific class or method names instead of wildcards.
Mixing wildcards with method name prefixes incorrectly.
5fill in blank
hard

Fill all three blanks to define a @Before advice that runs before all public methods in the controller package.

Spring Boot
@Before("execution(public [1] com.example.controller.[2].[3](..))")
public void beforeControllerMethods() {
    System.out.println("Before controller method");
}
Drag options to blanks, or click blank then click option'
A*
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using specific return types like void limits matching.
Not using wildcards for class or method names.