Creating AOP proxies programmatically with the ProxyFactory - Java-Springs

It's easy to create AOP proxies programmatically using Spring.This enables you to use Spring AOP without dependency on Spring IoC.

The following listing shows creation of a proxy for a target object, with one interceptor and one advisor.The interfaces implemented by the target object will automatically be proxied:

roxyFactory factory = new ProxyFactory(myBusinessInterfaceImpl);
factory.addAdvice(myMethodInterceptor);
factory.addAdvisor(myAdvisor);
MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();

The first step is to construct an object of type org. spring frame work. aop. frame work. Proxy Factory.You can create this with a target object, as in the above example, or specify the interfaces to be proxied in an alternate constructor.

You can add advices (with interceptors as a specialized kind of advice) and/or advisors, and manipulate them for the life of the ProxyFactory.If you add an Introduction Interception Around Advisor, you can cause the proxy to implement additional interfaces.

There are also convenience methods on Proxy Factory (inherited from Advised Support) which allow you to add other advice types such as before and throws advice. Advised Support is the superclass of both Proxy Factory and Proxy Factory Bean.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java-Springs Topics