AOP, events, scheduling, and caching
Spring adds cross-cutting behavior around beans through proxies and supports events, tasks, schedules, and cache abstractions.
AOP
Aspect-oriented programming is useful for concerns applied consistently across many methods: transactions, security, metrics, tracing, or narrowly defined logging. A pointcut selects join points; advice runs before, after, or around them.
Avoid hiding core business flow in aspects. If reading the method cannot reveal that an order is published or a fee is charged, the design is surprising.
Events
Application events decouple in-process components. By default,
listeners run in the publisher's thread.
@TransactionalEventListener can bind handling to a
transaction phase. In-process events disappear if the process crashes;
use a durable broker/outbox for cross-service guarantees.
Scheduling and async
@Scheduled triggers recurring work. In multiple
replicas, every replica may run it unless coordination exists.
@Async uses an executor; configure pool size, queue,
rejection, context, and exception handling.
Caching
@Cacheable can avoid repeated work, but every cache
needs a key, TTL, invalidation, maximum size, consistency expectation,
and failure behavior.
Feynman check
A proxy is a gate adding checks. An event is a bell inside one building. A message broker is a postal service between buildings. A cache is a whiteboard copy that can become stale.