耗时监控
package cn.com.tcgroup.yunlu.commons;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
public class EfficiencyAOP {
private long time = 0;
private String className = null;
private String methodName = null;
public void begin(JoinPoint point){
time = System.currentTimeMillis();
Object target = point.getTarget();//拦截的实体类
className = target.getClass().getName();
methodName = point.getSignature().getName();//拦截的方法名称
Object[] args = point.getArgs();//拦截的方法参数
Class[] parameterTypes = ((MethodSignature)point.getSignature()).getMethod().getParameterTypes();//拦截的方法参数类型
Method m = null;
try {
m = target.getClass().getMethod(methodName, parameterTypes);//通过反射获得拦截的method
if (m.isBridge()) {//如果是桥,则要获得实际拦截的method
for (int i = 0; i < args.length; i++) {
Class genClazz = GenericsUtils.getSuperClassGenricType(target.getClass());
if(args[i].getClass().isAssignableFrom(genClazz)){
parameterTypes[i] = genClazz;
}
}
m = target.getClass().getMethod(methodName, parameterTypes);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public void end(){
System.out.println(className+"."+methodName + "耗时" + (System.currentTimeMillis()-time) + "毫秒");
}
}
<bean id="efficiencyAOP" class="cn.com.tcgroup.yunlu.commons.EfficiencyAOP"></bean>
<!-- 配置性能监视器 -->
<aop:config>
<aop:aspect id="test" ref="efficiencyAOP">
<aop:pointcut expression="execution (* cn.com.tcgroup.yunlu.*.*.*.*.*(..))" id="p"/>
<aop:before method="begin" pointcut-ref="p"/>
<aop:after method="end" pointcut-ref="p"/>
</aop:aspect>
</aop:config>
备注:GenericsUtils.java参见网址--
http://songjianyong.iteye.com/blog/1638417
分享到:
相关推荐
Spring AOP配置的实例,最基本的Spring AOP配置
springAOP配置实现动态代理,有利于熟悉动态代理原理,深入了解spring。
Spring AOP配置事务方法,描述了spring的事务配置,方便开发应用和数据库的连接管理。
利用SPring AOP配置切面的一个例子
里面包含了多种Spring AOP配置,十分详细。
SpringAop面向切面编程
spring aop配置常用jar包,但是spring官网不提供下载。
Spring aop 配置 Spring aspect 配置 Spring advisor 配置 Spring pointcut 配置
使用Spring配置文件实现AOP
Spring之AOP配置文件详解.txt Spring之AOP配置文件详解.txt 帮助你更快张握Java的学习!
@Component("userService")等价于在spring配置文件中定义一个<bean id="userService"/> @Resource(name="userDAO")将userDA注入进来 写一个拦截器的类 package com.spring.aop; import org.springframework....
aop 配置的重要概括,记录详细,有示例说明。
spring AOP详细说明
最近使用了springAOP编程,文档里面包含了springAOP的代码示例及详细注释说明,使用的是注解配置模式
NULL 博文链接:https://free9277.iteye.com/blog/1935297
spring-aop标签和配置文件两种方式实例,spring要求2.5及以上
SpringAop xml方式配置通知
spring配置文件的汇总,参考后对spring的配置将会学到很多
SpringAop配置事务管理,有两种配置方式。一种直接使用注解的方式,另外一种非注解