Spring MVC controller methods accespt different parameters that are injected before the method is invoked. Like HttpServletRequest
, HttpServletResponse
, java.security.Principal
, etc.
@RequestMapping("/test")
public String test(HttpServletRequest req, Principal user){}
How can I declare something that can be injected in a controlelr method?
@RequestMapping("/test")
public String test(MyCustomInjectable myInjectable){}
More on the specific case:
I want to parse the HttpServletRequest
in some servlet filter and construct an object that will be used in the controller method. More precisely I will parse a JWT token and access the claims.
There is an option to create custom HandlerMethodArgumentResolver
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With