SpringBoot 拦截 response 记录日志
Posted EvilTuzki
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot 拦截 response 记录日志相关的知识,希望对你有一定的参考价值。
废话不多说直接上代码
package com.gs.techpub.filter; import com.gridsum.techpub.utils.JsonUtil; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component @Aspect public class ResponseFilter { private Logger logger = LoggerFactory.getLogger(this.getClass()); @AfterReturning(returning = "ret", pointcut = "execution( * com.gs.techpub.controller.*.*(..))") public void doAfterReturning(Object ret) { logger.info("返回值 : " + JsonUtil.getInstance().toJson(ret)); } }
记得加上依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
以上是关于SpringBoot 拦截 response 记录日志的主要内容,如果未能解决你的问题,请参考以下文章