Java类动态代理框架 Smartproxy


Smartproxy 是一个 Java 的动态类和实例代理框架,类似 java.lang.reflect.Proxy 类所作的工作,但无需调用 InvocationHandler 接口。Smartproxy 通过底层对象提供对抽象类方法的重载。Smartproxy 使用 BCEL 类库。

  • Easy to use since there is not need to code an invocation handler, only the methods to be changed in the proxy.
  • Fast to execute since the smartproxy generated classes actually inherit from the abstract class and actually implement (in byte code) the delegation calls to the underlying object. As a result a proxy class generated by smartproxy is roughly equivalent to the same hand coded class while the jlrP generated classes are way slower (on a first test about 100 time slower on my machine).


// Create the proxy factory for the set on interface/implementor.

ProxyFactory factory = ProxyFactory.getInstance(SimpleImplementor.class, SimpleInterface.class);

// Creates an underlying object.

SimpleInterface base = new SimpleBaseClass();

// Proxify the underlying object.

SimpleInterface proxified = (SimpleInterface) factory.createProxy(new Object[] { base });


昵    称: