concept CGLib in category dependency injection

appears as: CGLib
Dependency Injection: Design Patterns Using Spring and Guice

This is an excerpt from Manning's book Dependency Injection: Design Patterns Using Spring and Guice.

Interceptors trap the normal behavior of a method and decorate it with the provided advice. They are applied via the use of dynamic proxies, which are generated subclasses of the original class that reroute method calls through an interceptor. The Java core library provides a simple proxying mechanism for generating subclasses of interfaces on the fly. More sophisticated proxy libraries are available for proxying concrete classes too (CGLib is one example).

Proxying Classes with CGLib

A couple of useful libraries provide tools for proxying. Guice and Spring both use a popular library called CGLib[2] to generate proxies under the hood. CGLib fills in nicely where Java’s proxy mechanism falls short. It’s able to generate the bytecode that would dynamically extend an existing class and override all of its methods, dispatching them to an interceptor instead.

2 CGLib stands for Code Generation Library. Find out more about CGLib at http://cglib.sourceforge.net.