java.lang.IllegalStateException: No thread-bound request found, exception in aspect

前端 未结 5 1171
不知归路
不知归路 2021-02-02 08:20

Following is my aspect:

    @Configurable
    @Aspect
    public class TimingAspect {

        @Autowired
        private HttpServletRequest httpServletRequest;
         


        
5条回答
  •  醉梦人生
    2021-02-02 09:13

    @M. Deinum answer doesn't work for me. I use these code instead

    RequestAttributes attribs = RequestContextHolder.getRequestAttributes();
    if (RequestContextHolder.getRequestAttributes() != null) {
        HttpServletRequest request = ((ServletRequestAttributes) attributes).getRequest();
        return request.getRemoteAddr();
    }
    

提交回复
热议问题