Scrivio Interview library

Aspect-oriented programming

25 questions in 7 subtopics.

Proxy-based AOP

ConceptFoundations6 min read
How does Spring apply features such as @Transactional, @Async and @Cacheable to your beans?
DebuggingFoundations6 min read
@Transactional on a private method has no effect. Why? Would it work on a protected or package-private method?
InternalsIntermediate6 min read
What is the difference between Spring AOP's proxy model and AspectJ's model, and what are the practical consequences?
LeadershipAdvanced6 min read
A team wants to implement audit logging, tenant filtering and authorisation checks with custom aspects across all services. What guidance would you give?

JDK dynamic proxies vs CGLIB

ConceptFoundations6 min read
When does Spring use a JDK dynamic proxy and when does it use CGLIB, and what does Spring Boot do by default?
InternalsIntermediate6 min read
With a CGLIB proxy, a bean's constructor logs a line. In older Spring versions it logged twice. Why, and what changed?
DebuggingIntermediate6 min read
An application fails with BeanNotOfRequiredTypeException: Bean named 'orderService' is expected to be of type 'OrderServiceImpl' but was actually of type 'jdk.proxy2.$Proxy87'. Explain and fix.
LeadershipPrincipal7 min read
Framework features that rely on runtime proxies cause recurring confusion: self-invocation, final classes, type mismatches. Over the long term, would you push teams towards more explicit code instead of proxy-based annotations?

Pointcut expressions

CodingFoundations6 min read
Write pointcut expressions for: (1) all public methods in classes in com.acme.service and sub-packages, (2) methods annotated with @Audited, (3) all methods of beans whose name ends with 'Client'.
ConceptIntermediate6 min read
Explain the difference between the within, @within, @annotation, this and target pointcut designators in Spring AOP.
DesignAdvanced7 min read
Your company has a shared aspect with the pointcut execution(* com.company..*.*(..)) for logging. Services see high CPU and odd behaviour. How would you redesign it?
ScenarioPrincipal6 min read
An organisation-wide audit aspect has been in place for years with package-based pointcuts. A package rename silently stopped auditing in several services. How would you prevent this class of problem?

Advice types

ConceptFoundations6 min read
Describe the five advice types in Spring AOP and when each runs.
DebuggingFoundations6 min read
An @Around advice logs the method time, but every advised method now returns null. What is the bug?
@Around("@annotation(Timed)")
public void time(ProceedingJoinPoint pjp) throws Throwable {
long t = System.nanoTime();
pjp.proceed();
log(t);
}
CodingIntermediate6 min read
Write an @Around advice that retries a method up to three times on a TransientDataAccessException. What must the advised method guarantee?

Self-invocation problem

DebuggingFoundations5 min read
Why does no transaction start here?
@Service
class OrderService {
public void placeAll(List<Order> orders) {
orders.forEach(this::place);
}
@Transactional
public void place(Order o) { ... }
}
ConceptIntermediate6 min read
Compare the fixes for self-invocation: extracting a bean, self-injection, AopContext.currentProxy() and AspectJ mode. Which would you choose in a code review?
LeadershipAdvanced7 min read
Self-invocation bugs with @Transactional keep reaching production across teams. What would you put in place?

AspectJ weaving

ConceptIntermediate6 min read
What are compile-time, post-compile and load-time weaving in AspectJ, and how does Spring support load-time weaving?
DesignAdvanced7 min read
When would you choose AspectJ weaving over Spring's proxy-based AOP for a production system?
LeadershipPrincipal7 min read
Your company adopted AspectJ load-time weaving ten years ago for auditing and it now slows startup and blocks native images. How do you decide what to do?

Ordering aspects

ConceptFoundations6 min read
How do you control the order of two aspects that apply to the same method, and what does a lower order value mean?
DebuggingIntermediate7 min read
A retry aspect and @Transactional apply to the same method, but retries reuse a transaction that is already marked rollback-only. How do you fix the order?
DesignAdvanced7 min read
Your platform provides aspects for tracing, metrics, retries, transactions and security in shared starters. Design the ordering rules so teams get consistent behaviour.
LeadershipPrincipal7 min read
Proxies and aspects underpin many Spring features. Considering AOT compilation and native images, how do you see the long-term role of runtime proxies in Java frameworks?