zoukankan
html css js c++ java
最简单的动态代理实例(spring基于接口代理的AOP原理)
JDK的动态代理是基于接口的
package
com.open.aop;
public
interface
BusinessInterface
{
public
void
processBusiness();
}
目标对象
package
com.open.aop;
public
class
BusinessObject
implements
BusinessInterface
{
public
void
processBusiness()
{
System.out.println(
"
action
"
);
}
}
代理对象
package
com.open.aop;
import
java.lang.reflect.InvocationHandler;
import
java.lang.reflect.Method;
import
java.lang.reflect.Proxy;
public
class
LogHandler
implements
InvocationHandler
{
private
Object delegate;
public
Object binder(Object delegate)
{
this
.delegate
=
delegate;
return
Proxy.newProxyInstance(delegate.getClass().getClassLoader(),
delegate.getClass().getInterfaces(),
this
);
}
public
Object invoke(Object proxy, Method method, Object[] args)
throws
Throwable
{
Object obj
=
null
;
System.out.println(
"
对象方法调用前
"
);
try
{
obj
=
method.invoke(delegate, args);
}
catch
(Exception e)
{
}
System.out.println(
"
对象方法调用后
"
);
return
obj;
}
}
测试类
package
com.open.aop;
import
java.lang.reflect.InvocationHandler;
import
java.lang.reflect.Proxy;
public
class
Test
{
public
static
void
main(String[] args)
{
BusinessInterface bi
=
(BusinessInterface)
new
LogHandler()
.binder(
new
BusinessObject());
bi.processBusiness();
}
}
输出结果
对象方法调用前
action
对象方法调用后
查看全文
相关阅读:
Natas29 Writeup(Perl命令注入、00截断、绕过过滤)
Natas27 Writeup(mysql溢出截断漏洞)
Natas26 Writeup(PHP反序列化漏洞)
Natas25 Writeup(目录遍历、头部注入)
Natas24 Writeup(strcmp绕过漏洞)
yum提示Another app is currently holding the yum lock; waiting for it to exit
linux网站
fastdfs_5.05下载
sqlog连接虚拟机mysql服务
java知识博客网站(一些配置和学习的记录)
原文地址:https://www.cnblogs.com/shaohz2014/p/3582151.html
最新文章
熵、相对熵和交叉熵
损失函数的实例
神经网路的层数,损失函数(loss)
激活函数
代码说明(搭建神经网络的步骤)
搭建神经网络的步骤
《了不起的 nodejs》中 TwitterWeb 案例 bug 解决
node
视差滚动技术的简介及运用
Yeoman 官网教学案例:使用 Yeoman 构建 WebApp
热门文章
展望未来:使用 PostCSS 和 cssnext 书写 CSS
关于 devbridge
【模式匹配】更快的Boyer
【模式匹配】KMP算法的来龙去脉
Pig 实现关键词匹配
Pig + Ansj 统计中文文本词频
Natas33 Writeup(Phar反序列化漏洞)
Natas32 Writeup(Perl 远程代码执行)
Natas31 Writeup(Perl 远程命令执行)
Natas30 Writeup(sql注入)
Copyright © 2011-2022 走看看