使用BeanNameAutoProxyCreator配置自动代理时如果某个bean没有实现任何接口,比如
public classMyBean
{
}
则会报错java.lang.ClassNotFoundException:org.objectweb.asm.Type
当然引入cglib.jar和asm.jar是没有问题的,需要注意版本问题(我使用的cglib-2.2.2和asm-3.3.1)如果cglib和asm两个jar包版本不是匹配的有可能出现错误。
下面要讨论的是不实现任何接口的bean为什么要使用asm包,而实现了某些接口则可以不适用asm包。
DefaultAopProxyFactory.class
publicAopProxy createAopProxy(AdvisedSupport config) throws AopConfigException{
if(config.isOptimize() || config.isProxyTargetClass() ||hasNoUserSuppliedProxyInterfaces(config)) {
//需要优化或者直接代理的类而不是接口或者用户没有提供接口或者用户提供了一个接口是SpringProxy
ClasstargetClass = config.getTargetClass();
if(targetClass == null) {
thrownew AopConfigException("TargetSource cannot determ