Skip to content

Instantly share code, notes, and snippets.

@malkusch
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkusch/9822102 to your computer and use it in GitHub Desktop.
Save malkusch/9822102 to your computer and use it in GitHub Desktop.
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SSCCE.ContextConfig.class)
@WebAppConfiguration
public class SSCCE {
@Autowired
private SingletonBean singletonBean;
@Configuration
@ComponentScan(basePackageClasses=SSCCE.class)
public static class ContextConfig {
}
@Component
public static class SingletonBean {
@Autowired
private RequestBean bean;
}
@Component
@Scope(WebApplicationContext.SCOPE_REQUEST)
public static class RequestBean {
}
@Test
public void testInstantiation() {
}
}
@malkusch
Copy link
Author

This gist fails during application context initialization with a:

BeanCreationException: Error creating bean with name 'SSCCE.RequestBean': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment