package com.zf.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import com.zf.dao.PersonDao;
@Component
@Aspect
public class DaoAspect {
@Pointcut("execution(* com.zf.dao.PersonDao.*(..))")
public void daoPointCut(){};
@Before("daoPointCut()")
public void beforeDao(JoinPoint joinPoint){
PersonDao pd = (PersonDao)joinPoint.getTarget();
pd.setMessage("helloWorld");
System.out.println();
System.out.println("beforeDao...");
}
@AfterReturning("daoPointCut()")
public void afterDao(JoinPoint joinPoint){
System.out.println(joinPoint.getTarget() instanceof PersonDao);
System.out.println("afaterDao...");
}
@Around("daoPointCut()")
public Object daoAround(ProceedingJoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
System.out.println("argsLength: " + args.length);
for (Object object : args) { //得到目标对象
System.out.println(object + " -------------------------");
}
Object obj = null;
try {
obj = joinPoint.proceed(args);
} catch (Throwable e) {
e.printStackTrace();
}
return obj;
}
}
java进阶 http://www.javady.com/index.php/category/hign_xingneng
分享到:
相关推荐
spring AOP,注解方式的实现! 内部方法的拦截
使用Spring的注解方式实现AOP的细节
演示了spring对aop的支持,包括注解方式、基于xml方式。
关于AOP注解前置通知、后置通知、返回通知、异常通知的注解注释及应用
SpringAOP注解方式.zip,SpringAOP注解特棒例子
基于注解实现SpringAop基于注解实现SpringAop基于注解实现SpringAop
先引入Spring框架开发的基本开发包,再引入Spring框架的AOP的开发包
2、能够清楚的知道如何用spring aop实现自定义注解以及注解的逻辑实现 (需要知道原理的请看spring aop源码,此处不做赘述) 3、可在现有源码上快速进行功能扩展 4、spring boot,mybatis,druid,spring aop的使用
Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,AOP的原理就是java的动态代理机制
spring aop 通过注解实现的项目,这只是一个简单的例子。运行环境也简单。
SpringAOP的注解配置完成切面的编程,完成execution,annotation两种表达式的实例Ddemo
最近使用了springAOP编程,文档里面包含了springAOP的代码示例及详细注释说明,使用的是注解配置模式
springboot spring aop 拦截器 注解方式实现脱敏(涉及到:pom.xml -->application.properties --->启动类-->拦截器)
spring 注解 aop demo spring 注解 aop demo spring 注解 aop demo spring 注解 aop demo
Spring Mvc AOP通过注解方式拦截controller等实现日志管理
NULL 博文链接:https://panmingzhi0815.iteye.com/blog/1137649
spring aop样例.方便对springaop的了解和快速学习
spring aop注解所需要的三个jar包,aspectjrt.jar,aspectjweaver.jar,aopalliance.jar
spring boot AOP注解方式实现多数据源整合(从零开始搭建框架到配置多数据源实践小例子)
代码中有注解实例,spring框架实例,aop切片实例