MarcGiffing / wicket-spring-boot

Spring Boot starter for Apache Wicket
153 stars 62 forks source link

Cannot inject spring component with web scopes #138

Closed cadin81 closed 6 years ago

cadin81 commented 6 years ago

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.

MarcGiffing commented 6 years ago

It worked for me if I register a RequestContextListener bean.

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

From the Doucmentation: