title: How to log request body using spring boot and aspect
body: <p>I have created an aspect to log the request body passed in a controller function:</p>
  
  <p>This is what i am trying</p>
  
  <pre><code>@Pointcut("execution(* com.test.test.test.controller.*.* (..))")
    public void executeController() {}
  
    @Pointcut("execution(* com.test.test.common.exception.*.* (..))")
    public void executeExceptionAdvice() {}
  
    @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.PostMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.PutMapping) ||"
        + "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)")
    public void logRequestMapping() {}
  
    @Before("logRequestMapping() &amp;&amp; executeController() &amp;&amp; args(..,@RequestBody requestBody) ")
    public void logRequestBody(JoinPoint joinPoint, Object requestBody) {
      LOGGER = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
      LOGGER.info("Method : {},Request Body:{}",
          LOGGER.getName() + "." + joinPoint.getSignature().getName(),
          MaskingUtil.jsonifyAndMask(requestBody));
    }
  </code></pre>
  
  <p>Now instead of matching with @RequestBody spring is matching arguments with <strong>..</strong> i.e. generalize arguments and logging everything which is passed instead of the request body.I want to log only request body and if it is null the it won't print anything.</p>