It’s very common to refer to some Spring features as “magic.” How else could you add functionality like caching at the method level with nothing but a single annotation? Magic!

Proxying Technologies

Over time, I’ve come to learn the names of some of the magic ✨ that facilitates the amazing features of Spring that drive up the productivity of engineers and light a fire under the velocity of development teams.

JDK Dynamic Proxies and CGLIB.

Proxies in Spring are an implementation of the Proxy design pattern and help facilitate the paradigm of Aspect-Oriented Programming.

Benefits of Proxies ➕

  • Provide a surrogate to control access to an object
  • Acts as a wrapper to protect the real component from complexity( i.e. Real component only contains core business logic and not unrelated cross-cutting logic like logging)
  • Provides a level of indirection to support distributed, controlled, or modified access
  • Can act as a placeholder for “expensive to create” objects to allow for lazy creation
  • Can be used to verify permissions before allowing access to secured objects
  • Can inject additional functionality when an object is accessed such as logging, caching, transaction management, etc.

#java #software-development #programming #spring #spring-framework

Spring Dependency Injection Demystified Part 1: Proxying
1.30 GEEK