Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use AOP in spring

Shulou Source: shulou.com Published: 2022-06-02 09:22:47 11月13日 Update

It is believed that many inexperienced people have no idea about how to use AOP in spring. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

/ / AOP section: when there are multiple sections, @ Order (I) is annotated to identify the priority of the section. The lower the value of I, the higher the priority @ Order (5) @ Aspect@Componentpublic class SysAspect {@ Pointcut ("execution (public * com.zypcy.expend.controller.*.* (..)")) Public void log () {} private static final org.slf4j.Logger logger = LoggerFactory.getLogger (SysAspect.class); / / count the processing time of the request ThreadLocal startTime = new ThreadLocal (); @ Before ("log ()") public void doBefore (JoinPoint joinPoint) throws Throwable {startTime.set (System.currentTimeMillis ()); / / receive the request and record the request content ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes () HttpServletRequest request = attributes.getRequest (); / / record the content of the request System.out.println ("Aspect_URL:" + request.getRequestURL () .toString ()); System.out.println ("Aspect_Method:" + request.getMethod ()) } @ AfterReturning (returning = "ret", pointcut = "log ()") public void doAfterReturning (Object ret) {/ / after processing the request, return the content System.out.println ("method return value:" + JSON.toJSONString (ret) + ", method execution time:" + (System.currentTimeMillis ()-startTime.get ();}} after reading the above content, have you mastered how to use AOP in spring? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Content method priority aspect time more problem processing helpless for this reason multiple for this skills identification notes articles experience industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info macOS OPPO Reno Huawei