Get header from request in service layer of Spring Boot application
You can inject HttpServletRequest
object in your service layer like this :
@Autowired
HttpServletRequest request;
private void method() {
request.getHeader("headerName");
}
but remember, that bean HttpServletRequest
has HTTP request scope. So, you can't inject that into asynchronous methods etc, because it will throw Runtime Exception
.
hope it helps.