springboot之aspectj实现的aop
程序员文章站
2022-03-19 21:36:03
...
①需要的依赖包
<!--AOP-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
②编写切面类
@Aspect
@Component
public class CheckUserRoleAop {
@Pointcut("execution(public * com.example.demo.controller.HelloSpringBoot.*(..))")
public void pointCut(){}
/**
* 环绕通知需要返回值(返回值的类型与被代理类相同)
* @param joinPoint
* @return
* @throws Throwable
*/
@Around("pointCut()")
public String checkRoleAop(ProceedingJoinPoint joinPoint) throws Throwable {
return (String) joinPoint.proceed();
}
}