3

As answered in this question, I supposed that I could inject request/session beans in my test classes when using @WebAppConfuguration (or @WebIntegrationTest for spring boot). I does not work tough.

Here is my test class config:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SocialInfoSrvAppConfig.class)
@WebIntegrationTest
//@IntegrationTest
//@WebAppConfiguration
public class FacebookServiceTest {
...
    @Inject
    private Facebook facebook;
...
}

Here is my app config:

@SpringBootApplication
// @EnableResourceServer
@EnableJms
@EnableSocial
@EnableWebMvc
public class SocialInfoSrvAppConfig extends SpringCommonApp {

}

I get this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.facebook': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is 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.

as if I could not inject this request scoped bean into my test.

What am I missing?

Community
  • 1
  • 1
rvcoutinho
  • 326
  • 1
  • 10
  • I have the same problem, also the same occurs if we use thread locals in the injected objects. Did you find the right solution? – Thomas Weglinski Jan 26 '16 at 23:08
  • Not yet. Working in other tasks before going back to this. Hope we get some help before that. – rvcoutinho Jan 27 '16 at 00:35
  • Please show us the exact configuration for the `Facebook` bean (i.e., the entire declaration for the `@Bean` method, including all annotations on the method). The reason I ask is that you may have neglected to configure it as a _scoped proxy_. – Sam Brannen Jan 28 '16 at 15:36
  • Facebook bean is part of spring-social. – rvcoutinho Jan 28 '16 at 15:53
  • Anyway, I made a wrapper for the Facebook bean and configured it as proxied: --- @Component @Scope(proxyMode = ScopedProxyMode.INTERFACES, scopeName = "request") public class FacebookProxyImpl implements FacebookProxy {...} ---- It could not be injected either. – rvcoutinho Jan 28 '16 at 16:36

0 Answers0