@Override public BeanDefinition parse(Element element, ParserContext parserContext) { RootBeanDefinition beanDefinition = new RootBeanDefinition(); beanDefinition.setBeanClass(CustomScopeConfigurer.class); beanDefinition.setScope("singleton"); Map<String, Object> scopes = new HashMap<>(); scopes.put("thread", new SimpleThreadScope()); beanDefinition.getPropertyValues().add("scopes", scopes); parserContext.getRegistry().registerBeanDefinition("CustomScopeConfigurer", beanDefinition); return beanDefinition; }
@Override public void prepareTestInstance(TestContext testContext) throws Exception { if (testContext.getApplicationContext() instanceof GenericApplicationContext) { GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); Scope requestScope = new SimpleThreadScope(); beanFactory.registerScope("request", requestScope); Scope sessionScope = new SimpleThreadScope(); beanFactory.registerScope("session", sessionScope); } }
@Override public void prepareTestInstance(TestContext testContext) { if (testContext.getApplicationContext() instanceof GenericApplicationContext) { GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new SimpleThreadScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SimpleThreadScope()); } }
@Bean public CustomScopeConfigurer configurer() { CustomScopeConfigurer toRet = new CustomScopeConfigurer(); Map<String, Object> map = new HashMap<String, Object>(); map.put(KarakuBaseConfiguration.SCOPE_CONVERSATION, new SimpleThreadScope()); map.put(KarakuBaseConfiguration.SCOPE_CONVERSATION_MANUAL, new SimpleThreadScope()); map.put(WebApplicationContext.SCOPE_SESSION, new SimpleThreadScope()); toRet.setScopes(map); return toRet; }
public SimpleThreadScopeConfigurer() { super(); super.setScopes(new HashMap<String, Object>() { { put("thread", new SimpleThreadScope()); } }); }
@Bean public CustomScopeConfigurer customScopeConfigurer() { final CustomScopeConfigurer configurer = new CustomScopeConfigurer(); configurer.addScope("session", new SimpleThreadScope()); return configurer; }
@Bean static CustomScopeConfigurer customScopes() { final CustomScopeConfigurer configurer = new CustomScopeConfigurer(); final Map<String, Object> scopes = new HashMap<String, Object>(); scopes.put("foobarScope", new SimpleThreadScope()); configurer.setScopes(scopes); return configurer; }