Spring's IoC and AOP are must-know topics in interviews. But most people just memorize the concepts.
IoC (Inversion of Control)
What interviewers want to hear isn't just "Inversion of Control means handing object creation to the container." They want:
- Why IoC is needed: Decoupling. No need to
newdependency objects—inject them via configuration or annotations. - Three ways of DI: Constructor injection (recommended), Setter injection, Field injection (
@Autowired). - Bean lifecycle: Instantiation → Property injection → Aware callbacks → Initialization → Usage → Destruction.
- Bean scopes: singleton (default), prototype, request, session.
Bonus points: Being able to explain how circular dependencies are resolved—the three-level cache.
AOP (Aspect-Oriented Programming)
What interviewers want to hear:
- What problem AOP solves: Cross-cutting concerns—logging, transactions, permission checks.
- Core concepts: Aspect, Join Point, Advice, Pointcut.
- Proxy patterns: JDK dynamic proxy (interface-based) vs CGLIB proxy (class-inheritance-based).
- Practical application:
@Transactionalis implemented via AOP, opening/committing/rolling back transactions before and after method execution.
Hands-On Skills Matter More Than Memorization
If you can write a simple AOP aspect on the spot during an interview to print method execution time, you'll score much higher:
@Aspect
@Component
public class LoggingAspect {
@Around("execution(* com.example.service.*.*(..))")
public Object logTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
System.out.println(joinPoint.getSignature() + " took " + (System.currentTimeMillis() - start) + "ms");
return result;
}
}
Don't just memorize textbook answers. Write it once, and you'll remember it.
Comments
Comments are closed.