基于AspectJ自定义注解
package com.aspectj.demo.aspect; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MonitorMethod {
String value() default "";
}
package com.aspectj.demo.aspect; import java.lang.reflect.Method; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; @Aspect
public class MethodExecutionTime { // @Around("execution(* *.*(..)) && @annotation(com.aspectj.demo.aspect.MonitorMethod)")
@Around("execution(* *.*(..)) && @annotation(method)")
public Object profile(ProceedingJoinPoint pjd,MonitorMethod method) throws Throwable {
Object result = null;
System.out.println(method.value());
// 这里可以获取方法名
System.out.println(pjd.getSignature().getName());
System.out.println(pjd.getTarget());
// 获取方法名
Method[] methods = pjd.getSignature().getDeclaringType().getMethods();
System.out.println(methods[0]); // 获取参数信息
Object[] args = pjd.getArgs();
for (Object o : args) {
System.out.println(o.toString());
}
try {
// System.out.println("前置通知");
result = pjd.proceed();
// System.out.println("后置通知");
} catch (Throwable e) {
// System.out.println("异常通知");
}
// System.out.println("返回通知");
return result;
}
}
package com.aspectj.demo.aspect;
public class StockService {
@MonitorMethod(value="1111111111")
public String getBaseInfo(String a) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "";
}
}
基于AspectJ自定义注解的更多相关文章
- 基于AspectJ的注解方式进行AOP开发
-------------------siwuxie095 基于 AspectJ 的注解方式进行 AOP 开发 ...
- Spring_day03--课程安排_基于aspectj的注解aop_Spring的jdbcTemplate操作
Spring_day03 上节内容回顾 今天内容介绍 基于aspectj的注解aop Spring的jdbcTemplate操作 增加 修改 删除 查询 Spring配置c3p0连接池和dao使用jd ...
- Spring_AOP基于AspectJ的注解开发&JDBC的模板使用&事务管理(学习笔记3)
一:AOP基于AspectJ的注解开发 1,简单的实例: 1)引入相应的jar包 2)在配置文件里引入相关约束 <beans xmlns="http://www.springfra ...
- day39-Spring 08-Spring的AOP:基于AspectJ的注解
基于AspectJ的注解的开发要重点掌握. 这些表达式肯定要应用在我们的某些个增强上. 学习AspectJ也是两种形式:一种是XML,一种是注解.AspectJ的增强,就是那些通知的类型.Aspect ...
- 十四 Spring的AOP的基于AspectJ的注解开发
Spring的AOP的基于AspectJ的注解开发 创建项目,引入jar包 编写目标类.切面类 配置目标类.切面类 在注解文件里开启AOP的开发 <?xml version="1.0& ...
- 2.基于AOP自定义注解Annotation的实现
上一篇中分析了AOP的实现原理, 总结为: 判断对象是否需要被代理?@Aspect注解的实现是根据切入点表达式 代理之后需要做什么,就是那些通知,本质上是实现了MethodInterceptor的拦截 ...
- Spring的AOP基于AspectJ的注解方式开发2
参考自黑马培训机构 上一篇博客提到了在配置文件中开启aop的注解开发,以及简单使用了@Before,@Aspect 这是为了告诉spring为前置通知和切面类 接下来介绍aop的注解的通知类型,和切入 ...
- Spring的AOP基于AspectJ的注解方式开发1
参考自黑马培训机构 创建项目,引入jar包 编写目标类,切面类并完成配置 package spring.day2_aop2; /* * 编写目标类 */ public class OrderDao { ...
- AOP——基于AspectJ的注解来实现AOP操作
1.使用注解方式实现AOP操作 第一步:创建对象 <!-- 创建对象 --> <bean id="book" class="com.bjxb.aop.B ...
随机推荐
- ADO.NET 快速入门(七):使用数据库事务
数据库事务用于控制数据提交到数据库.例如,在标准的账户程序,账户的借贷必须同时完成.由于电脑偶尔发生故障(电力中断.网络中断,等等),可能有些记录被更新或者添加,但是另外一些没有.为了避免这些情况,可 ...
- C#的图片拼接
貌似很长时间没有写博客了,感觉再不写都要废了. 这段时间确实迷茫得不行,整天混混顿顿的,逃避这个逃避那个,话说已经辞职一个月了…… 这几天在学用libgdx做安卓上的游戏,感觉缺少一个图片拼接的工具, ...
- Codeforces Round #328 (Div. 2) D. Super M 虚树直径
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
- delphi 01设置 字体属性
设置/获取 字体属性 名称 大小 粗体 斜体 下划线 删除线 颜色1 颜色2 uses MSHTML; //设置 //------------------------------------- ...
- 使用自定义的BaseAdapter实现LIstView的展示
http://stephen830.iteye.com/blog/1141394 使用自定义的BaseAdapter实现LIstView的展示 实现以下功能点: 1.通过自定义的BaseAdapter ...
- [Angular 2] Import custom module
The application structure: in app.module.ts: import { NgModule} from "@angular/core"; impo ...
- 升级Flash Builder 4.7中的AIR SDK
原文地址:http://helpx.adobe.com/flash-builder/kb/overlay-air-sdk-flash-builder.html本文并没有“忠于”原文翻译. Flash ...
- The internals of Python string interning
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...
- VBA Excel 单元格操作
1. 设置单元格边框: .Range("A3:M" & l + 1).SelectWith Selection.Borders() .LineStyle = xlConti ...
- Android(java)学习笔记85:案例拨号程序
手机拨号程序:(只有程序代码) package cn.itcast.phone; import android.app.Activity; import android.content.Intent; ...