springboot之aspectj实现的aop

①需要的依赖包

<!--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();

}

}

猜你喜欢

转载自blog.csdn.net/weixin_42228338/article/details/81384521