Spring Framework
ProxyFactory
Construct a proxy factory for a trusted local target and configure advice. Spring 7.0.9 instructional lab; source-reviewed, not executed.
Formal Syntax & Structure
java syntaxjava
new ProxyFactory(new Target())Working Example
Example Snippetjava
package lab.spring;import org.aopalliance.intercept.MethodInterceptor;import org.springframework.aop.framework.ProxyFactory;public class ProxyDemo { public interface Service { void outer(); void inner(); } public static class Target implements Service { public void outer() { System.out.println("outer"); inner(); } public void inner() { System.out.println("inner"); } } public static void main(String[] args) { var factory = new ProxyFactory(new Target()); factory.setInterfaces(Service.class); factory.setProxyTargetClass(false); factory.addAdvice((MethodInterceptor) invocation -> { System.out.println("before " + invocation.getMethod().getName()); return invocation.proceed(); }); Service service = (Service) factory.getProxy(); service.outer(); service.inner(); }}