java – 在spring框架中使用代理(动态代理)的意思是什么?

我不知道在春天使用代理的意思.什么是高效?

解决方法

dynamic proxy是JDK的一个特色.可以使用 an invocation handler实现接口.

A dynamic proxy class (simply referred
to as a proxy class below) is a class
that implements a list of interfaces
specified at runtime when the class is
created,with behavior as described
below. A proxy interface is such an
interface that is implemented by a
proxy class. A proxy instance is an
instance of a proxy class. Each proxy
instance has an associated invocation
handler object,which implements the
interface InvocationHandler.

动态代理有一些开销.对于大多数用例,开销并不重要.真正的问题在于(使用)动态代理使应用程序难以理解和调试.例如,动态代理将在堆栈跟踪中显示多行.

动态代理通常用于实现decorators.其中一个例子是Spring中的AOP. (我不想进入AOP的细节,不会使用AOP术语来保持简单).某些问题在一个类中实施,并在许多地方使用.动态代理(和调用处理程序)只是粘贴代码(由Spring提供)来拦截方法调用. (实际上,动态代理只是这个功能的实现细节,即时生成类是实现它的另一种可能性.)

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...