Spring Framework中的CGLIB是什么? [英] What is CGLIB in Spring Framework?

查看:337
本文介绍了Spring Framework中的CGLIB是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是CGLIB?它与Spring有何关系?使用Spring Framework时,我们是否必须明确定义CGLIB的用法?

解决方案

参考Spring 代理目标类属性设置为true会使基于CGLIB的代理生效.

通过注释:

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class AppConfig {
   // ...
}

不需要将CGLIB添加到您的类路径中.从Spring 3.2开始,CGLIB被重新打包并包含在spring-core JAR中.

您也可以查看./p>

What is CGLIB and how it is related to Spring? Do we have to define usage of CGLIB explicitly when using Spring Framework?

解决方案

Ref Spring docs. What is CGLIB & how is it related to Spring?

CGLIB is a code generation library. Spring uses CGLIB, to generate proxies.

Spring AOP defaults to using standard JDK dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied.

Yes, you have to tell spring to use CGLIB based proxies explicitly.

Via xml:

<aop:aspectj-autoproxy proxy-target-class="true"/> proxy-target-class property is set to true will cause CGLIB-based proxying to be in effect.

Via Annotation:

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class AppConfig {
   // ...
}

There is no need to add CGLIB to your classpath. As of Spring 3.2, CGLIB is repackaged and included in the spring-core JAR.

You may have look at this too.

这篇关于Spring Framework中的CGLIB是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆