Posts

Showing posts from April, 2026

WHY does Spring “skip” the annotation? What is actually happening in memory?

🧠 Step 1 — What Spring really creates You write: @ Service public class OrderService { @ Transactional public void placeOrder () { } @ CacheEvict ( value = "productCache" , key = "#productId" ) public void updateProduct ( int productId ) { } } ❗ What actually exists at runtime Spring creates two objects : 1. Real Object: OrderService 2. Proxy Object: OrderService$$SpringProxy 👉 Important When you do: @ Autowired OrderService orderService ; 👉 You are getting: OrderService$$SpringProxy NOT your real class. 🧩 Step 2 — What’s inside the proxy? The proxy wraps your method calls like this: public class OrderServiceProxy { private OrderService target ; public void updateProduct ( int productId ) { // 🔥 Cache logic injected here evictCache ( "productCache" , productId ); target . updateProduct ( productId ); } public void placeOrder () { startTra...