微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/java/124688.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐