'@RequestAttribute return null for own attribute created by AOP

I would like to read the request attribute in the controller that I added in spring AOP. But is still return null. Maybe I read this data incorrectly? Maybe I can't use annotation for that?

Aop:

@Around(value = "putMappingPointcut(putMapping)", argNames = "joinPoint,putMapping")
public Object checkPutHeaders(ProceedingJoinPoint joinPoint, PutMapping putMapping)    throws Throwable {

final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
final HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(requestAttributes)).getRequest();
final String apiKey = request.getHeader(API_KEY);


 final String company = apiKeyProviderService.getCompanyBy(apiKey);
 request.setAttribute("company", company);

 return joinPoint.proceed();
}

Controller:

@PutMapping("/accounts")
public Company authenticate(@RequestAttribute(name = "company", required = false) String company,
                            @RequestBody Authentication authentication) {
....

}

If I add HttpServletRequest to my controller and call getAttribut("company") I receive correct code for company.

Thanks for the help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source