In a controller, I can access all the @RequestHeader
s using the following code
@RestController
public class MyController {
@RequestMapping(value = "/mypath", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity moveEnrollment(@RequestHeader Map<String, String> headers) {
..invoke business logic
}
}
How do I inject the headers into a Spring service bean which is not a controller? Otherwise i need to pass on this hashmap all over the place.
I know that I can inject HttpServletRequest
and then get the headers but it would be easier if it can be injected directly.