package com
.czh
.GClib_Utils
;
import net
.sf
.cglib
.proxy
.Enhancer
;
import net
.sf
.cglib
.proxy
.MethodInterceptor
;
import net
.sf
.cglib
.proxy
.MethodProxy
;
import java
.lang
.reflect
.Method
;
import net
.sf
.cglib
.proxy
.Callback
;
import net
.sf
.cglib
.proxy
.Enhancer
;
import net
.sf
.cglib
.proxy
.MethodInterceptor
;
import net
.sf
.cglib
.proxy
.MethodProxy
;
import java
.lang
.reflect
.Method
;
public class gclib implements MethodInterceptor {
private Class
targe;
public Object newInstance
(Class
targe){
this.targe
=targe
;
return Enhancer
.create(targe
, this);
}
@Override
public Object
intercept(Object o
, Method method
, Object
[] objects
, MethodProxy methodProxy
) throws Throwable
{
methodProxy
.invoke(targe
.newInstance(), objects
);
System
.out
.println("chlibdaili ");
return null
;
}
}
测试类
package com
.czh
.GClib_Utils
;
import com
.czh
.domain
.impl
.userDaoimpl
;
import com
.czh
.domain
.userDao
;
public class cglibDemo {
public static void main(String
[] args
) {
gclib gclib
= new gclib();
userDaoimpl o
= (userDaoimpl
) gclib
.newInstance(userDaoimpl
.class);
o
.eat("S");
o
.run();
}
}
转载请注明原文地址: https://mac.8miu.com/read-497777.html