0

Is this possible to define a Spring bean in applicationContext.xml that takes an instance of HttpRequest as a constructor argument?

The bean I'm trying to create is an instance of org.keycloak.adapters.springsecurity.facade.WrappedHttpServletRequest. The reason behind this is that I want to use Spring AOP to intercept a method that's invoked from that class. Is this possible?

That's the constructor code:

public WrappedHttpServletRequest(HttpServletRequest request) {
    Assert.notNull(request, "HttpServletRequest required");
    this.request = request;
}
Luis Celestino
  • 87
  • 1
  • 10
  • 1
    You can autowire it, @Autowired private HttpServletRequest httpServletRequest; this is considered as bad practice though, the recommended way is to somehow pass it as request parameter to controller https://stackoverflow.com/questions/8504258/spring-3-mvc-accessing-httprequest-from-controller – Borislav Stoilov Dec 18 '18 at 21:33
  • Thank you Borislav. I changed the approach, but will remember this next time I need to do something like that again. – Luis Celestino Dec 21 '18 at 12:14

0 Answers0