使用BeanNameAutoProxyCreator实现方法日志代理
来源:互联网 发布:sql server2005精简版 编辑:程序博客网 时间:2024/06/05 19:42
使用BeanNameAutoProxyCreator实现方法执行前和执行后的日志记录
首先实现方法执行前和执行后的日志记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package
com.andeveloper.springdemo.aop;
import
java.lang.reflect.Method;
import
org.apache.log4j.Logger;
import
org.springframework.aop.AfterReturningAdvice;
public
class
LogMethodAfterReturningAdvice
implements
AfterReturningAdvice {
private
static
Logger logger = Logger.getLogger(LogMethodAfterReturningAdvice.
class
);
@Override
public
void
afterReturning(Object returnValue, Method method,
Object[] args, Object target)
throws
Throwable {
logger.info(method.getName() +
"执行结果为"
+ returnValue);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package
com.andeveloper.springdemo.aop;
import
java.lang.reflect.Method;
import
org.apache.log4j.Logger;
import
org.springframework.aop.MethodBeforeAdvice;
public
class
LogMethodBeforeAdvice
implements
MethodBeforeAdvice {
private
static
Logger logger = Logger.getLogger(LogMethodBeforeAdvice.
class
);
@Override
public
void
before(Method arg0, Object[] arg1, Object arg2)
throws
Throwable {
String args =
""
;
if
(arg1 !=
null
) {
for
(
int
i =
0
; i < arg1.length; ++i) {
if
(i != arg1.length -
1
) {
args += arg1[i] +
","
;
}
else
{
args += arg1[i];
}
}
}
logger.info(arg0.getName() +
"方法开始执行,参数为["
+ args +
"]"
);
}
}
配置BeanNameAutoProxyCreator代理,实现所有以Controller,Service,Dao结尾的方法自动代理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<
bean
id
=
"logMethodBefore"
class
=
"com.andeveloper.springdemo.aop.LogMethodBeforeAdvice"
/>
<
bean
id
=
"logAfterReturning"
class
=
"com.andeveloper.springdemo.aop.LogMethodAfterReturningAdvice"
/>
<
bean
class
=
"org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
>
<
property
name
=
"beanNames"
>
<
list
>
<
value
>*Controller</
value
>
<
value
>*Service</
value
>
<
value
>*Dao</
value
>
</
list
>
</
property
>
<
property
name
=
"interceptorNames"
>
<
list
>
<
value
>logMethodBefore</
value
>
<
value
>logAfterReturning</
value
>
</
list
>
</
property
>
</
bean
>
0 0
- 使用BeanNameAutoProxyCreator实现方法日志代理
- 使用BeanNameAutoProxyCreator实现spring的自动代理
- 使用BeanNameAutoProxyCreator实现spring的自动代理
- 使用BeanNameAutoProxyCreator实现spring的自动代理
- spring aop(八)--使用BeanNameAutoProxyCreator创建代理
- 自动创建代理--BeanNameAutoProxyCreator
- BeanNameAutoProxyCreator自动创建事务代理
- Java使用注解和动态代理实现方法调用时的日志记录示例
- spring 配置实例1(使用BeanNameAutoProxyCreator自动代理,比较省时省力的做法)
- spring中BeanNameAutoProxyCreator和AnnotationAwareAspectJAutoProxyCreator两种AOP代理方式使用总结
- spring用BeanNameAutoProxyCreator自动创建事务代理
- 用BeanNameAutoProxyCreator自动创建事务代理
- 用BeanNameAutoProxyCreator自动创建事务代理
- 用BeanNameAutoProxyCreator自动创建事务代理
- spring用BeanNameAutoProxyCreator自动创建事务代理
- spring用BeanNameAutoProxyCreator自动创建事务代理
- spring用BeanNameAutoProxyCreator自动创建事务代理
- 用BeanNameAutoProxyCreator自动创建事务代理
- <web前端>当背景图片为渐变色图片时,为避免浏览器大小问题,可以选择使用<CSS>实现渐变色,教程如下
- 基于用户名/密码认证和流量控制的OpenVPN系统配置
- CSS+div页面排版
- 转载 jQuery$冲突问题
- 获取相册图片或拍照
- 使用BeanNameAutoProxyCreator实现方法日志代理
- css样式学习笔记四
- Android系统权限配置详解
- 地图发布与切片
- xshell,winscp无法用root用户登录
- linux下tar.gz、tar、bz2、zip等解压缩命令
- python 安装ggplot包
- 有20个数组,每个数组有500个元素,升序排列,现在在这20*500个数中找出排名前500的数。
- hibernate--悲观锁-乐观锁的并发问题