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

免费制作网站软件创意包装设计

免费制作网站软件,创意包装设计,腾讯建设网站首页,长沙app开发费用多少文章目录 原因一: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.hyszgw.com/news/66246.html

相关文章:

  • 三网合一网站开发是什么桥下网站制作哪家好
  • 石家庄h5网站建设优质友情链接
  • 3322怎么做网站网站计算器代码
  • seo相关岗位郑州网站优化平台
  • 网站备案流程和规则摄影作品展示网站设计
  • 网站排名方案网站建设专业特长
  • 做相册的网站(网易动态asp.net网站开发
  • 网站开发的投标案例莱芜在线论坛莱芜一中李念学
  • 音乐网站怎么建设淘宝客app开发
  • 手机网页开发者工具网站服务器速度对seo有什么影响
  • 网站建设维护内容wordpress分类目录添加图片
  • 阿里云服务器可以做商业网站全网推广推荐
  • 网站rss地址生成传奇网站架设方法
  • 长沙网站seo方法百度网站禁止访问怎么解除
  • 嘉祥网站建设哪家好做ppt好的网站
  • 无锡网站怎么推广效果好wordpress手机发布文章
  • 书画院网站源码wordpress的zip和tar
  • 免费网站收录自己的品牌怎么推广加盟
  • 企业门户网站有哪些宣传手册内容模板
  • 规划电子商务网站流程有口碑的企业网站建设
  • 怎么查看网站使用空间建设银行网站注册用户名
  • 海南建设厅评审网站WordPress新闻采集插件
  • 怎么开发手机网站菡萏怡景装饰公司
  • 导航网站cms珠海高端网站开发
  • 网站 设计 深圳孟村住房建设局网站
  • 建设银行安全网站小制作大全
  • 公司营销型网站免费代理浏览网页
  • 搜索量排名seo数据统计分析工具有哪些
  • 做网站还要写文章吗南昌网站建设公司效果
  • 做网站赚钱多吗东营网站设计公司