Spring / Spring7 basics Interview questions
Define an Aspect in Spring AOP?
An Aspect is a module that captures a cross-cutting concern - logic like logging, security checks, or transaction handling that would otherwise be scattered across many unrelated classes - and applies it declaratively at defined points in the program, called join points.
@Aspect @Component public class LoggingAspect { @Before("execution(* com.shop.service.*.*(..))") public void logCall(JoinPoint jp) { System.out.println("Calling: " + jp.getSignature()); } }
An aspect is defined by combining a pointcut expression, which selects which join points to match, with advice, which is the code to run at those points. Spring implements aspects using proxies by default, so AOP only intercepts calls that go through a Spring-managed bean reference, not internal method-to-method calls within the same class.
More Related questions...