ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP的细节)
2009-02-18 21:39
1516 查看
感谢ITCAST发布的免费视频
例外通知会屏蔽后置通知
使用环绕通知可以代替前面所提的所有通知类型
@Aspect
public class MyInterceptor {
@Pointcut("execution (* cn.service.impl.PersonServiceBean.*(..))")
public void anyMethod() {} //declare a pointcut
@Before("anyMethod()") //declare a before advice, parameter is the name of the pointcut
public void doAccessCheck() {
System.out.println("before advice");
}
@After("anyMethod()")
public void doAfterReturning() {
System.out.println("after advice");
}
@AfterReturning("anyMethod()")
public void doAfter() {
System.out.println("final advice");
}
@AfterThrowing("anyMethod()")
public void doThrow() {
System.out.println("throw advice");
}
@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
//if () {check authority
System.out.println("in");
Object result = pjp.proceed();
System.out.println("out");
//}
return result;
}
}
如何得到输入参数,返回结果,抛出的异常?
@Aspect
public class MyInterceptor {
@Pointcut("execution (* cn.service.impl.PersonServiceBean.*(..))")
public void anyMethod() {} //declare a pointcut
@Before("anyMethod() && args(name)") //declare a before advice, parameter is the name of the pointcut
public void doAccessCheck(String name) {
System.out.println("before advice");
System.out.println(name);
}
@After("anyMethod()")
public void doAfterReturning() {
System.out.println("after advice");
}
@AfterReturning(pointcut = "anyMethod()", returning = "result")
public void doAfter(String result) {
System.out.println("final advice");
System.out.println(result);
}
@AfterThrowing(pointcut = "anyMethod()", throwing = "ex")
public void doThrow(Exception ex) {
System.out.println("throw advice");
}
@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
//if () {check authority
System.out.println("in");
Object result = pjp.proceed();
System.out.println("out");
//}
return result;
}
}
例外通知会屏蔽后置通知
使用环绕通知可以代替前面所提的所有通知类型
@Aspect
public class MyInterceptor {
@Pointcut("execution (* cn.service.impl.PersonServiceBean.*(..))")
public void anyMethod() {} //declare a pointcut
@Before("anyMethod()") //declare a before advice, parameter is the name of the pointcut
public void doAccessCheck() {
System.out.println("before advice");
}
@After("anyMethod()")
public void doAfterReturning() {
System.out.println("after advice");
}
@AfterReturning("anyMethod()")
public void doAfter() {
System.out.println("final advice");
}
@AfterThrowing("anyMethod()")
public void doThrow() {
System.out.println("throw advice");
}
@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
//if () {check authority
System.out.println("in");
Object result = pjp.proceed();
System.out.println("out");
//}
return result;
}
}
如何得到输入参数,返回结果,抛出的异常?
@Aspect
public class MyInterceptor {
@Pointcut("execution (* cn.service.impl.PersonServiceBean.*(..))")
public void anyMethod() {} //declare a pointcut
@Before("anyMethod() && args(name)") //declare a before advice, parameter is the name of the pointcut
public void doAccessCheck(String name) {
System.out.println("before advice");
System.out.println(name);
}
@After("anyMethod()")
public void doAfterReturning() {
System.out.println("after advice");
}
@AfterReturning(pointcut = "anyMethod()", returning = "result")
public void doAfter(String result) {
System.out.println("final advice");
System.out.println(result);
}
@AfterThrowing(pointcut = "anyMethod()", throwing = "ex")
public void doThrow(Exception ex) {
System.out.println("throw advice");
}
@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
//if () {check authority
System.out.println("in");
Object result = pjp.proceed();
System.out.println("out");
//}
return result;
}
}
相关文章推荐
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP入门)
- Spring学习笔记(14)----使用Spring的注解方式实现AOP
- ITCAST视频-Spring学习笔记(使用CGLIB实现AOP功能与AOP概念解释)
- ITCAST视频-Spring学习笔记(使用JDK中的Proxy技术实现AOP功能)
- ITCAST视频-Spring学习笔记(使用Spring配置文件实现AOP)
- spring学习笔记7--使用spring进行面向切面的(AOP)编程(1)注解方式实现
- ITCAST视频-Spring学习笔记(编码剖析@Resource注解的实现原理)
- Spring学习笔记(三)Spring注解方式实现AOP
- 使用Spring的注解方式实现AOP的细节
- 使用Spring的注解方式实现AOP的细节
- (转)使用Spring的注解方式实现AOP的细节
- (9) 使用Spring的注解方式实现AOP入门 以及 细节
- spring学习(八)—AOP通过注解方式实现
- 使用Spring的注解方式实现AOP
- Spring视频学习(九)使用Spring注解方式管理事务与传播行为详解
- 使用Spring的注解方式实现AOP入门
- ITCAST视频-Spring学习笔记(使用构造器装配属性)
- Spring的注解方式实现AOP的细节
- spring 4.0 AOP (使用AspectJ的注解方式 的aop实现)简单实例
- Spring AOP 使用注解的方式实现用户日志的两种方法