AOP和动态代理
2015-07-04 11:35
302 查看
JDK动态代理
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import com.wadata.hdc.dxs.service.TransportService;
/**
* 动态代理处理器
* @author yong.zhang
*
*/
public class HessianTransportHandler implements InvocationHandler {
private Object target;
public HessianTransportHandler(Object target){
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("前=====");
Object result=method.invoke(target, args);
System.out.println("后=====");
return result;
}
//创建代理
public static Object createProxy(Object target){
return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
new HessianTransportHandler(target));
}
public static void main(String[] args) {
TransportService createProxy = (TransportService) HessianTransportHandler.createProxy(new HessianTransportService());
createProxy.transport(null);
}
}
使用SPRING通知模块化横切点
http://lrf8933.blog.163.com/blog/static/68973963201102542010524/
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import com.wadata.hdc.dxs.service.TransportService;
/**
* 动态代理处理器
* @author yong.zhang
*
*/
public class HessianTransportHandler implements InvocationHandler {
private Object target;
public HessianTransportHandler(Object target){
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("前=====");
Object result=method.invoke(target, args);
System.out.println("后=====");
return result;
}
//创建代理
public static Object createProxy(Object target){
return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
new HessianTransportHandler(target));
}
public static void main(String[] args) {
TransportService createProxy = (TransportService) HessianTransportHandler.createProxy(new HessianTransportService());
createProxy.transport(null);
}
}
使用SPRING通知模块化横切点
http://lrf8933.blog.163.com/blog/static/68973963201102542010524/
相关文章推荐
- Tip:outlook IMAP和POP3客户端不支持Exchange OAB
- linux解压文件
- 集成tomcat插件到eclipse
- 学习 Docker - 入门
- CentOS6.3挂载读写NTFS分区
- Opencv3.0.0+Visual Studio 2013+win8.1 64位 配置大致思路
- OpenCV_连通区域分析与标记(Connected Component Analysis-Labeling)
- Eclipse中插件的使用:maven /ant /tomcat
- Eclipse中插件的使用:maven /ant /tomcat
- usermod -g和gpasswd -a的区别
- shell中的小括号与大括号
- sync_binlog
- phpStudy for Linux (lnmp+lamp一键安装包) 符合國內
- WARNING: CAN’T OPEN CONFIG FILE: /USR/LOCAL/SSL/OPENSSL.CNF
- Apache之安装
- shell学习三十五天----波浪号展开与通配符
- 关于使用xcode7进行真机测试出现 "could not find developer disk image"
- opencv之haar特征+AdaBoos分类器算法流程(一)
- shell中的括号知多少
- Apache之火狐的卸载