Type of proxies available in Spring:
JDK Proxy | CGLib proxy |
also called dynamic proxies comes with JDK only for Interfaces all interfaces are proxies | extra lib included in Spring can intercept protected and public methods used when interfaces are not available cannot be applied to final classes or methods used by Spring Boot |
Key | JDK dynamic proxy | CGLIB proxy |
---|---|---|
Basic | It can be only proxy by interface so target class needs to implement interface | It can create proxy by subclassing |
Package | It is available with the Java | It is a third library. |
Performance | It is a bit slow than CGLIB proxy | It is faster than JDK dynamic proxy |
Final | Final class and Final method can not be proxy | Final class and Final method can not be proxy |
Use case | Spring uses JDK proxy when is class is implementing one or more interface | Spring uses CGLib proxy when class in not implementing interface |