java spring切面编程
package com.example.test.config;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AnnotationPointcut {
@Before("execution(* com.example.test.job..*(..))")
public void before(){
System.out.println("========方法执行前=========");
}
@After("execution(* com.example.test.job..*(..))")
public void after(){
System.out.println("========方法执行后=========");
}
@Around("execution(* com.example.test.server.Impl.*(..))")
public void around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("---------环绕前---------");
pjp.proceed();
System.out.println("---------环绕后---------");
}
}
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AnnotationPointcut {
@Before("execution(* com.example.test.job..*(..))")
public void before(){
System.out.println("========方法执行前=========");
}
@After("execution(* com.example.test.job..*(..))")
public void after(){
System.out.println("========方法执行后=========");
}
@Around("execution(* com.example.test.server.Impl.*(..))")
public void around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("---------环绕前---------");
pjp.proceed();
System.out.println("---------环绕后---------");
}
}
Aspect切面注解,声明是一个切面类
Component 注入spring框架中
Before、After 这里注解是对指定的类方法执行的时候执行方法内容