当前位置:网站首页 > 产品管理 > 正文

springaop日志管理(springbootaop日志)



package com.cppdy.log; import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @Aspect @Component public class WebLogAspect { @Pointcut("execution(public * com.cppdy.controller..*.*(..))") public void webLog() { } @Before("webLog()") public void doBefore(JoinPoint joinPoint) throws Throwable { // 接收到请求,记录请求内容 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); // 记录下请求内容 System.out.println("URL:" + request.getRequestURL().toString()); System.out.println("HTTP_METHOD:" + request.getMethod()); System.out.println("IP:" + request.getRemoteAddr()); Enumeration<String> enu = request.getParameterNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); System.out.println("name:" + name + ",value:" + request.getParameter(name)); } } @AfterReturning(returning="ret",pointcut="webLog()") public void doAfterReturning(Object ret)throws Throwable { //处理完请求,返回内容 System.out.println("RESPONSE:"+ret); } }
到此这篇springaop日志管理(springbootaop日志)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • kvm虚拟化管理系统(kvm虚拟化平台搭建)2025-06-12 10:27:10
  • 产品经理好学吗(产品经理好学吗知乎)2025-06-12 10:27:10
  • 小米14文件管理在哪里找(小米14文件管理在哪里找到)2025-06-12 10:27:10
  • 产品经理入门书籍推荐(产品经理入门书籍推荐理由)2025-06-12 10:27:10
  • 文件管理系统软件怎么删除(文件管理系统文件可以删除吗)2025-06-12 10:27:10
  • 怎么打开任务管理器快捷键(怎么打开任务管理器快捷键win7)2025-06-12 10:27:10
  • 文件管理date访问限制(文件管理访问data)2025-06-12 10:27:10
  • 工具类产品有哪些商品或品牌(工具类产品有哪些商品或品牌呢)2025-06-12 10:27:10
  • 产品经理入门证书(产品经理资格证)2025-06-12 10:27:10
  • 工具类产品(工具类产品举例3个)2025-06-12 10:27:10
  • 全屏图片