Junior — Middle
Have you used aspect-oriented programming with Spring AOP?
sobes.tech AI
Answer from AI
Spring AOP (Aspect-Oriented Programming) allows injecting additional functionality (aspects) into code without modifying business logic. For example, logging, transactions, security, etc.
Experience with it typically includes:
- Defining aspects using annotations (
@Aspect), where pointcuts and advices are described. - Configuring Spring bean proxies to apply aspects.
- Using different types of advices:
@Before,@After,@Around.
An example of a simple logging aspect:
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.service.*.*(..))")
public void logBeforeMethod(JoinPoint joinPoint) {
System.out.println("Method call: " + joinPoint.getSignature().getName());
}
}
This aspect will output a message before any method call in the com.example.service package.