MarcGiffing/wicket-spring-boot

Cannot inject spring component with web scopes

cadin81 opened this issue · 1 comments

Hello!

I'm unable to inject a spring component with an web scope (request, session...). I got the following exception:

Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
	at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
	at org.springframework.web.context.request.SessionScope.get(SessionScope.java:55) ~[spring-web-5.0.6.RELEASE.jar:5.0.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
	... 45 common frames omitted

I've done my own configuration of wicket on spring boot and it worked fine.

It worked for me if I register a RequestContextListener bean.

@Bean
	public RequestContextListener requestContextListener() {
		return new RequestContextListener();
	}

From the Doucmentation:

  • This listener is mainly for use with third-party servlets, e.g. the JSF FacesServlet.

  • Within Spring's own web support, DispatcherServlet's processing is perfectly sufficient.