当前位置: 首页 > news >正文

无锡网站建设方案服务百度人工客服在哪里找

无锡网站建设方案服务,百度人工客服在哪里找,南宁网站建设nnit30,网站开发l论文文章目录 原因一:CGlib不需要接口原因二:CGlib效率高原因三:JDK代理会导致注解失效如果希望使用JDK代理扩展AOP in Spring Boot, is it a JDK dynamic proxy or a Cglib dynamic proxy?SpringSpringBoot 原因一:CGlib不需要接口 …

文章目录

  • 原因一:CGlib不需要接口
  • 原因二:CGlib效率高
  • 原因三:JDK代理会导致注解失效
  • 如果希望使用JDK代理
  • 扩展
  • AOP in Spring Boot, is it a JDK dynamic proxy or a Cglib dynamic proxy?
      • Spring
      • SpringBoot

原因一:CGlib不需要接口

Spring动态代理默认使用CGlib,是因为它可以代理那些没有实现任何接口的类,而JDK动态代理仅能代理实现了接口的类。

原因二:CGlib效率高

CGlib相对于JDK动态代理来说,在代理类的创建和执行的速度上更快,因此在某些情况下,使用CGlib代理可以提高系统性能。

原因三:JDK代理会导致注解失效

如果Spring是JDK代理,那么就会导致某些注解失效。

如果希望使用JDK代理

  • Spring可以设置proxyTargetClass属性为false来强制使用JDK代理。
  • SpringBoot的AOP 默认使用 cglib,且无法通过proxyTargetClass进行修改。
    如果想修改的话,在Spring配置文件中添加spring.aop.proxy-target-class=false。

——————————————————End————————————————


扩展

AOP in Spring Boot, is it a JDK dynamic proxy or a Cglib dynamic proxy?

As we all know, the underlying AOP is dynamic proxies, and there are two ways to implement dynamic proxies in Java:

  • JDK-based dynamic proxy
  • Dynamic proxy based on Cglib

The biggest difference between these two is that JDK-based dynamic proxies require the object being proxied to implement an interface, while Cglib-based dynamic proxies do not require the object being proxied to implement an interface.

So, how is AOP implemented in Spring? Is it a dynamic proxy based on JDK or a dynamic proxy based on Cglib?

Spring

Let’s start with the conclusion that dynamic proxies in Spring, which one to use, are divided into cases.

If the proxy object implements the interface, then use the JDK dynamic proxy, otherwise it is the Cglib dynamic proxy.
If the proxy object does not implement an interface, then it is a direct Cglib dynamic proxy.

SpringBoot

Spring Boot and Spring are the same, so is it the same strategy for dynamic proxies? Sorry, it’s not really the same.

The handling of this issue in Spring Boot, with Spring Boot 2.0 as the node, is not the same.

Before Spring Boot 2.0, the code for automating the configuration of Aop looked like this (Spring Boot 1.5.22.RELEASE)

@Configuration
@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class })
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
public class AopAutoConfiguration {@Configuration@EnableAspectJAutoProxy(proxyTargetClass = false)@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false",matchIfMissing = true)public static class JdkDynamicAutoProxyConfiguration {}@Configuration@EnableAspectJAutoProxy(proxyTargetClass = true)@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true",matchIfMissing = false)public static class CglibAutoProxyConfiguration {}}

As you can see, this automation configuration is mainly discussing the value of the spring.aop.proxy-target-class property in the application.properties configuration file.

The @ConditionalOnProperty annotation is what does the trick. To illustrate a few of the properties in this annotation.

  • prefix: The prefix of the configuration file.
  • name: the name of the configuration file, and prefix together form the key of the configuration.
  • having: the value of the expected configuration. If the actual configuration is the same as the value of having, then the configuration will take effect, otherwise it will not.
  • matchIfMissing: if the developer did not configure it in application.properties, then this configuration class will take effect or not.

Based on the introduction as above, it is easy to see that.

  • If the developer has set spring.aop.proxy-target-class to false, then the JDK proxy is used.
  • If the developer has spring.aop.proxy-target-class set to true, then the Cglib proxy is used.
    = If the developer did not configure the spring.aop.proxy-target-class property in the first place, then the JDK proxy is used.
    This was the case before Spring Boot 2.0.

Let’s look at the situation after Spring Boot 2.0 (inclusive) (Spring Boot 2.0.0.RELEASE).

@Configuration
@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class,AnnotatedElement.class })
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
public class AopAutoConfiguration {@Configuration@EnableAspectJAutoProxy(proxyTargetClass = false)@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = false)public static class JdkDynamicAutoProxyConfiguration {}@Configuration@EnableAspectJAutoProxy(proxyTargetClass = true)@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = true)public static class CglibAutoProxyConfiguration {}}

As you can see, most of the configuration is the same, with one area that is not quite the same, and that is the value of the matchIfMissing property.
As you can see, starting with Spring Boot 2.0, if the user does not configure anything, the Cglib proxy is used by default.

来自Springboot的一篇英语文章

http://www.khdw.cn/news/41172.html

相关文章:

  • 做视频网站收费标准学校网站建设
  • 邯郸网站建设多少钱seo站外优化最主要的是什么
  • 做网站的岗位叫什么seo是什么职业
  • 做企业网站一般要多少钱培训机构招生方案范文
  • 对伊利网站建设建议有什么平台可以发布推广信息
  • 深圳网站建设公司联seo排名优化培训价格
  • 人才网站建设策划书重庆快速排名优化
  • 门户类网站有哪些万网官网
  • 网站建设提议网络推广的常用方法
  • 温州网站建设温州网站制作百度新闻最新消息
  • 网站开发的发展的前景青岛网站制作设计
  • 什么做网站开发百度合作平台
  • 帝国cms官方网站北大青鸟培训机构靠谱吗
  • 过年做那些网站能致富seo推广方法
  • wordpress 下载工具seo实战培训王乃用
  • 黄埔网站建设公司今日新闻头条新闻最新
  • 什么叫个人网站软件什么叫友情链接
  • 网站营销策略组合推广策划方案
  • 除了红动中国还有哪些设计网站关键词在线查询
  • 长沙自助建站哪家好企业文化培训
  • 聊城做网站公司聊城博达百度热搜电视剧
  • 建站价格会差下载百度极速版免费安装
  • 专业简历模板网站的seo优化报告
  • 国外可以做推广的网站百度指数搜索
  • 新衡阳网站黑帽seo培训大神
  • 网络销售工作内容台州seo排名公司
  • 建立网站需要多少钱稻挺湖南岚鸿有名软件推广赚钱
  • 银川网站建设公司福州seo网站管理
  • 什么软件做美食视频网站百度官网网站
  • 网站开发培训 价格百度认证有什么用