加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 16:38:29 所属栏目:Java 来源:网络整理
导读:我不知道在春天使用代理的意思.什么是高效? 解决方法 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 speci
我不知道在春天使用代理的意思.什么是高效?

解决方法

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提供)来拦截方法调用. (实际上,动态代理只是这个功能的实现细节,即时生成类是实现它的另一种可能性.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读