javaspringspring-mvc

What is the equivalent of @Context annotation from JAX-RS in Spring to inject HttpServletRequest?


In JAX-RS resource classes we can use

@Context
private HttpServletRequest request;

to be able to access details from the HTTP request.

What is the equivalent of the above line in Spring Boot? I don't want to add HttpServletRequest as argument in each method of my REST controller class.


Solution

  • Have you tried @Autowired?

    @Autowired
    private HttpServletRequest request;