基于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 ...
随机推荐
- Struts 2.x异常:Unable to load configuration..../WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/struts-plugin.xml:30:119
Struts 2.x异常:Unable to load configuration..../WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/strut ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- URAL 1780 G - Gray Code 找规律
G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- 关于c#调用C++代码的一些应用的体会
1.dll函数的导入: 关键字:unmanaged code ; managed code; 具体应用类:System.Runtime.InteropServices 具体使用方法: ...
- ListView 文件重命名
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Control ...
- <Android>关于EditText中setInputType和setSingleLine的冲突
近期自己开发了一个带有删除button的EditText,一方面须要设置为SingleLine,还有一方面又须要设置输入类型,起先在xml文件里设置了android:inputType类型,在自己定义 ...
- iOS开发——UI篇OC篇&layoutSubviews和drawRect
layoutSubviews和drawRect 首先两个方法都是异步执行.layoutSubviews方便数据计算,drawRect方便视图重绘. layoutSubviews在以下情况下 ...
- 编写3个不同版本的程序,令其均能输出ia的元素
#include<iostream> #include<vector> #include<string> using namespace std; int main ...
- 项目源码--Android本地音乐播放器
下载源码 技术要点: 1.本地音乐播放与管理 2.支持在线下载 3.非库音频流的解码 4. UI控件的综合使用 5. HTTP通信模块 6. Mysql数据库的综合使用 7. 后台服务技术 8. 源码 ...