Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use AOP in spring

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report