I was reading some articles about Spring AOP and encountered this:
AOP proxy: the object created by AOP to implement the aspect contracts. In Spring, proxy objects can be JDK dynamic proxies or CGLIB proxies. By default, the proxy objects will be JDK dynamic proxies, and the object being proxied must implement an interface, that will also be implemented by the proxy object. But a library like CGLIB can be used to create proxies by subclassing too, so an interface is not needed.
Could you look at the following structure and imagine that we want to advise bar()
method.
public interface Foo {
void foo();
}
public class FooImpl implements Foo {
@Override
public void foo() {
System.out.println("");
}
public void bar() {
System.out.println("");
}
}
Does it mean that in this case CGLIB proxy will be used?
Since JDK dynamic proxy isn't able to implement any interface in order to override bar()
method.