Why do i need cglib (Spring AOP) to have multiple test classes?

≡放荡痞女 提交于 2019-12-05 04:17:37
Alex Barnes

Spring requires the CGLIB jars because it's using CGLIB to proxy your beans. This happens if you configure spring to use this mechanism in your applicationContext.xml or if Spring needs to proxy a class which implements no interfaces. The Spring documentation for this is here and provides a very clear explantation.

In order to use JDK dynamic proxies ensure that any proxied classes implement an appropriate interface and that you're not forcing Spring to use CGLIB through configuration.

My guess is that spring adds its to your class at runtime, and this is why it need the cglib library (it is used for bytecode manipulation and code injection, see here)

Spring definately will use the proxy mechanism for some of your classes.

But, as of Spring version 3.2 the CGLIB sources are repackaged and added to the spring-core by default, so you don't need to add the CGLIB library to your classpath manually.

By the way, as the spring blog entry of Michael Isvy and this issue report state, the CGLIB project is not active any more. In future versions Spring will use Javassist by default.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!