Access HttpServletRequest object inside Aspect. Which one is better solution between two solutions mentioned

  1. I'm not sure that the first method works. Even if you can autowire HttpServletRequest this way, you'll have to make your aspect request-scoped.

  2. I think the best option would be to use RequestContextHolder:

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    

    This method uses a thread-local storage already populated by Spring and doesn't need any changes in your method signature.