Spring creates proxy using CGlib despite class implements multiple interfaces

35 views Asked by At

In my application, I have a class X that implements interface A and interface B. I’ve implemented an aspect using spring AOP and AspectJ with a pointcut on every method from the interface A.

While debugging the app, I noticed that Spring creates a proxy using CGLIB instead of JDK Dynamic Proxy. What’s the reason of such behaviour? Shouldn’t be the proxy created as Dynamic Proxy instead, as the class X implements an interfaces? I don’t understand it.

1

There are 1 answers

2
kriegaex On

Probably, you use Spring Boot, not plain Spring. In contrast to Spring proper, Boot defaults to CGLIB even for interface proxies, which needs to be overridden. More specifically, you need to put this into your application.properties:

spring.aop.proxy-target-class=false

See also my answers here: