转自:https://blog.csdn.net/licheng989/article/details/28929411

在Bean中有代码

  1. public abstract Axe getAxe();  


在配置文件中有

  1. <!-- 指定getAxe方法返回steelAxe  
  2. 每次调用getAxe方法将获取新的steelAxe对象 -->  
  3. <lookup-method name="getAxe" bean="steelAxe"/>  

 

这样可以协调作用域不同的Bean.但是运行报错

  1. nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter  


导入cglib-2.2.0.jar包后,继续报错

  1. nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type  

 

原因是Spring中的cglib-nodep-2.x.x.jar与Hibernate中的cglib-2.2.jar相冲突! 

两种框架整合时Spring中的cglib-nodep-2.x.x.jar是必须的,取消Hibernate中的cglib-2.2.jar即可 

所以,移除cglib-2.2.jar,导入cglib-nodeo-2.2.jar就好了。

下载cglib-nodeo2.2.jar和cglib-2.2.jar


利用lookup方法注入可以让Spring容器重写容器中的Bean的抽象方法,返回查找容器中其他Bean的结果,被查找的Bean通常是一个non-singleton Bean,Spring通过使用CGLIB库修改客户端的二进制码,从而实现上述的要求。


CGLIB库

cglib(Code Generation Library)是一个强大的,高性能,高质量的Code生成类库。它可以在运行期扩展Java类与实现Java接口。
cglib封装了asm,可以在运行期动态生成新的class。
cglib用于AOP,jdk中的proxy必须基于接口,cglib却没有这个限制。

...

这里有一篇博文介绍得很详细CGlib简单介绍


posted on 2017-10-15 16:06  Sharpest  阅读(1874)  评论(0编辑  收藏  举报